mariadb/storage
Yuchen Pei d0fcac4450
MDEV-35422 Fix spider group by handler trying to use fake group by fields
This is a fixup of MDEV-26345 commit
77ed235d50.

In MDEV-26345 the spider group by handler was updated so that it uses
the item_ptr fields of Query::group_by and Query::order_by, instead of
item. This was and is because the call to
join->set_items_ref_array(join->items1) during the execution stage,
just before the execution replaces the order-by / group-by item arrays
with Item_temptable_field.

Spider traverses the item tree during the group by handler (gbh)
creation at the end of the optimization stage, and decides a gbh could
handle the execution of the query. Basically spider gbh can handle the
execution if it can construct a well-formed query, executes on the
data node, and store the results in the correct places. If so, it will
create one, otherwise it will return NULL and the execution will use
the usual handler (ha_spider instead of spider_group_by_handler). To
that end, the general principle is the items checked for creation
should be the same items later used for query construciton. Since in
MDEV-26345 we changed to use the item_ptr field instead of item field
of order-by and group-by in query construction, in this patch we do
the same for the gbh creation.

The item_ptr field could be the uninitialised NULL value during the
gbh creation. This is because the optimizer may replace a DISTINCT
with a GROUP BY, which only happens if the original GROUP BY is empty.
It creates the artificial GROUP BY by calling create_distinct_group(),
which creates the corresponding ORDER object with item field aligning
with somewhere in ref_pointer_array, but leaving item_ptr to be NULL.
When spider finds out that item_ptr is NULL, it knows there's some
optimizer skullduggery and it is passed a query different from the
original. Without a clear contract between the server layer and the
gbh, it is better to be safe than sorry and not create the gbh in this
case.

Also add a check and error reporting for the unlikely case of item_ptr
changing from non-NULL at gbh construction to NULL at execution to
prevent server crash.

Also, we remove a check added in MDEV-29480 of order by items being
aggregate functions. That check was added with the premise that spider
was including auxiliary SELECT items which is referenced by ORDER BY
items. This premise was no longer true since MDEV-26345, and caused
problems such as MDEV-29546, which was fixed by MDEV-26345.
2024-12-03 10:32:42 +11:00
..
archive MDEV-33746 Supply missing override markings 2024-06-20 11:32:13 -04:00
blackhole MDEV-34348: my_hash_get_key fixes 2024-11-23 08:14:22 -07:00
cassandra MDEV-34348: my_hash_get_key fixes 2024-11-23 08:14:22 -07:00
columnstore MDEV-33091 pcre2 headers - handle columnstore 2024-09-05 12:14:06 +10:00
connect MDEV-34700 Connect SQLite3 MTR test fails due to various charset/collation related output changes 2024-12-01 13:52:41 +04:00
csv MDEV-34348: Miscellaneous fixes 2024-11-23 08:14:23 -07:00
example MDEV-33746 Supply missing override markings 2024-06-20 11:32:13 -04:00
federated MDEV-34348: my_hash_get_key fixes 2024-11-23 08:14:22 -07:00
federatedx MDEV-34348: my_hash_get_key fixes 2024-11-23 08:14:22 -07:00
heap MDEV-34348: Consolidate cmp function declarations 2024-11-23 08:14:22 -07:00
innobase MDEV-26516: WSREP: Record locking is disabled in this thread, but the table being modified 2024-11-28 01:02:35 +01:00
maria MDEV-34348: Fix casts relating to tree_walk_action 2024-11-23 08:14:23 -07:00
mroonga MDEV-34348: my_hash_get_key fixes 2024-11-23 08:14:22 -07:00
myisam MDEV-34348: Fix casts relating to tree_walk_action 2024-11-23 08:14:23 -07:00
myisammrg MDEV-34348: Consolidate cmp function declarations 2024-11-23 08:14:22 -07:00
oqgraph Extract some of #3360 fixes to 10.5.x 2024-11-21 22:43:56 +11:00
perfschema MDEV-34348: my_hash_get_key fixes 2024-11-23 08:14:22 -07:00
rocksdb MDEV-34408: Facilitate the addition of warnings into the build system 2024-11-23 08:14:23 -07:00
sequence MDEV-33746 Supply missing override markings 2024-06-20 11:32:13 -04:00
sphinx MDEV-34348: my_hash_get_key fixes 2024-11-23 08:14:22 -07:00
spider MDEV-35422 Fix spider group by handler trying to use fake group by fields 2024-12-03 10:32:42 +11:00
test_sql_discovery MDEV-33746 Supply missing override markings 2024-06-20 11:32:13 -04:00
tokudb MDEV-31005: Make working cursor-protocol 2024-09-18 18:39:26 +07:00