1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

Factor TABLE_LIST creation from add_table_to_list

Ideally our methods and functions should do one thing, do that well,
and do only that.  add_table_to_list does far more than adding a
table to a list, so this commit factors the TABLE_LIST creation out
to a new TABLE_LIST constructor.  It then uses placement new()
to create it in the correct memory area (result of thd->calloc).
Benefits of this approach:
 1. add_table_to_list now returns as early as possible on an error
 2. fewer side-effects incurred on creating the TABLE_LIST object
 3. TABLE_LIST won't be calloc'd if copy_to_db fails
 4. local declarations moved closer to their respective first uses
 5. improved code readability and logical flow
Also factored a couple of other functions to keep the happy path
more to the left, which makes them easier to follow at a glance.
This commit is contained in:
Dave Gosselin
2024-04-12 11:35:02 -04:00
committed by Dave Gosselin
parent 8dda602701
commit a8a75ba2d0
5 changed files with 133 additions and 90 deletions

View File

@@ -4832,24 +4832,24 @@ public:
*/
bool copy_db_to(LEX_CSTRING *to)
{
if (db.str == NULL)
if (db.str)
{
/*
No default database is set. In this case if it's guaranteed that
no CTE can be used in the statement then we can throw an error right
now at the parser stage. Otherwise the decision about throwing such
a message must be postponed until a post-parser stage when we are able
to resolve all CTE names as we don't need this message to be thrown
for any CTE references.
*/
if (!lex->with_cte_resolution)
my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
return TRUE;
to->str= strmake(db.str, db.length);
to->length= db.length;
return to->str == NULL; /* True on error */
}
to->str= strmake(db.str, db.length);
to->length= db.length;
return to->str == NULL; /* True on error */
/*
No default database is set. In this case if it's guaranteed that
no CTE can be used in the statement then we can throw an error right
now at the parser stage. Otherwise the decision about throwing such
a message must be postponed until a post-parser stage when we are able
to resolve all CTE names as we don't need this message to be thrown
for any CTE references.
*/
if (!lex->with_cte_resolution)
my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
return TRUE;
}
/* Get db name or "". Use for printing current db */
const char *get_db()