[MDEV-27684] Spider: remove pattern str->reserve() then str->q_append() Created: 2022-01-30  Updated: 2023-03-29

Status: Stalled
Project: MariaDB Server
Component/s: Storage Engine - Spider
Fix Version/s: 10.11

Type: Task Priority: Major
Reporter: Nayuta Yanagisawa (Inactive) Assignee: Yuchen Pei
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-27184 Assertion `(old_top == initial_top (a... Closed
relates to MDEV-26384 Spider: add new query building helper... Closed

 Description   

Remove the following pattern that can be seen 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 makes the code less readable and is error-prone (e.g., MDEV-27184).



 Comments   
Comment by Sergei Golubchik [ 2022-01-30 ]

that'd be str->append(). q_append() means "quick append" that doesn't check if there's enough space and assumes the caller knows what he's doing. Invoking reserve() explicitly every time before q_append() makes little sense, one can just as well use append().

Comment by Nayuta Yanagisawa (Inactive) [ 2022-01-31 ]

Thank you for your comment.

I would like to replace all q_appends with append, but that would be too big of a change. So, I will make spider_string::q_append() behave exactly same as spider_string::append(). Then, I'd gradually remove q_apppend(). I will do this on 10.3+.

Comment by Nayuta Yanagisawa (Inactive) [ 2022-01-31 ]

I noticed that we cannot simply replace spider_string::q_append() with spider_string::append() because Spider relies on the fact that q_append() never call String::realloc_with_efraxtra_if_needed(). realloc_with_efraxtra_if_needed() might wipes the data, in String::Ptr, which is placed beyond String::str_length.

For example, the test spider.ha fails, if we do the simple replacement. That is because spider_mbase_share::append_table_name_with_adjusting() behaves wrongly.

Comment by Nayuta Yanagisawa (Inactive) [ 2022-01-31 ]

I think that we can avoid relying on the implicit assumption by using spider_string::replace() instead of spider_string::length() + spider_string::q_append(). However, I wouldn't like to make major change in GA older versions. So, I will limit the scope of the issue to 10.9+.

Comment by Sergei Golubchik [ 2022-01-31 ]

spider_string::q_append and other methods are modelled after String methods in sql/sql_string.h.

I think it'd be very confusing if methods with identical names (e.g. q_append) will start behaving differently in spider_string and String)

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