[MDEV-26384] Spider: add new query building helper function Created: 2021-08-17  Updated: 2022-01-30  Resolved: 2021-12-23

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - Spider
Fix Version/s: N/A

Type: Task Priority: Major
Reporter: Nayuta Yanagisawa (Inactive) Assignee: Nayuta Yanagisawa (Inactive)
Resolution: Won't Do Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-27684 Spider: remove pattern str->reserve()... Stalled
Epic Link: Spider Refactoring

 Description   

We do see the following anywhere in the Spider codebase.

if (str->reserve(SPIDER_SQL_WHERE_LEN))
  DBUG_RETURN(HA_ERR_OUT_OF_MEM);
str->q_append(SPIDER_SQL_WHERE_STR, SPIDER_SQL_WHERE_LEN);

This is messy and makes the code less readable. It would be better if we could write like this:

if (int err = str->append(SPIDER_SQL_WHERE_STR))
  DBUG_RETURN(err);
 
// multiple string can be appended at once
if (int err = str->append(SPIDER_SQL_IN_STR, SPIDER_SQL_OPEN_PAREN_STR))
  DBUG_RETURN(err);

The memory allocation should be automatically done in the append function. This automatic memory allocation should care about the performance. Possibly, it would allocate extra memory and reallocate memory only when it is necessary.



 Comments   
Comment by Nayuta Yanagisawa (Inactive) [ 2021-12-01 ]

The spider_string class already has such a function but the function seems to be used in nowhere.

bool spider_string::append(
  const char *s
) {
  DBUG_ENTER("spider_string::append");
  DBUG_PRINT("info",("spider this=%p", this));
  DBUG_ASSERT(mem_calc_inited);
  DBUG_ASSERT((!current_alloc_mem && !str.is_alloced()) ||
    current_alloc_mem == str.alloced_length());
  bool res = str.append(s, strlen(s));
  SPIDER_STRING_CALC_MEM;
  DBUG_RETURN(res);
}

Generated at Thu Feb 08 09:44:54 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.