1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-33971 NAME_CONST in WHERE clause replaced by inner item

Improve performance of queries like
  SELECT * FROM t1 WHERE field = NAME_CONST('a', 4);
by, in this example, replacing the WHERE clause with field = 4
in the case of ref access.

The rewrite is done during fix_fields and we disambiguate this
case from other cases of NAME_CONST by inspecting where we are
in parsing.  We rely on THD::where to accomplish this.  To
improve performance there, we change the type of THD::where to
be an enumeration, so we can avoid string comparisons during
Item_name_const::fix_fields.  Consequently, this patch also
changes all usages of THD::where to conform likewise.
This commit is contained in:
Dave Gosselin
2024-04-26 12:13:31 -04:00
committed by Dave Gosselin
parent a0a7b1c128
commit 02e38e2ece
20 changed files with 310 additions and 75 deletions

View File

@ -2668,6 +2668,33 @@ struct thd_async_state
};
enum class THD_WHERE
{
NOWHERE = 0,
CHECKING_TRANSFORMED_SUBQUERY,
IN_ALL_ANY_SUBQUERY,
JSON_TABLE_ARGUMENT,
FIELD_LIST,
PARTITION_FUNCTION,
FROM_CLAUSE,
DEFAULT_WHERE,
ON_CLAUSE,
WHERE_CLAUSE,
CONVERT_CHARSET_CONST,
FOR_SYSTEM_TIME,
ORDER_CLAUSE,
HAVING_CLAUSE,
GROUP_STATEMENT,
PROCEDURE_LIST,
CHECK_OPTION,
USE_WHERE_STRING, // ugh, a compromise for vcol...
};
class THD;
const char *thd_where(THD *thd);
/**
@class THD
For each client connection we create a separate thread with THD serving as
@ -2720,13 +2747,6 @@ public:
MDL_request *backup_commit_lock;
void reset_for_next_command(bool do_clear_errors= 1);
/*
Constant for THD::where initialization in the beginning of every query.
It's needed because we do not save/restore THD::where normally during
primary (non subselect) query execution.
*/
static const char * const DEFAULT_WHERE;
#ifdef EMBEDDED_LIBRARY
struct st_mysql *mysql;
@ -2882,12 +2902,15 @@ public:
const char *get_proc_info() const
{ return proc_info; }
// Used by thd_where() when where==USE_WHERE_STRING
const char *where_str;
/*
Used in error messages to tell user in what part of MySQL we found an
error. E. g. when where= "having clause", if fix_fields() fails, user
will know that the error was in having clause.
*/
const char *where;
THD_WHERE where;
/* Needed by MariaDB semi sync replication */
Trans_binlog_info *semisync_info;