Browse Source

MDEV-36307 MDEV-35452 Do not create spider group by handler when dealing with derived tables or view and at least one select item is constant

If one of the selected field is a MIN or MAX and it has been optimized
into a constant, it is not added to the temp table used by a group by
handler (GBH). The GBH therefore cannot store results to this missing
field.

On the other hand, when SELECTing from a view or a derived table,
TMP_TABLE_ALL_COLUMNS is set. If the query has no group by or order
by, an Item_temptable_field is created for this MIN/MAX field and
added to the JOIN. Since the GBH could not store results to the
corresponding field in the temp table, the value of this
Item_temptable_field remains NULL. And the NULL value is passed to the
record, then the temp row, and finally output as the (wrong) result.

To fix this, we opt to not creating a spider GBH when a view or
derived table is involved.

This fixes spider/bugfix.mdev_26345 for --view-protocol

Also fixed a comment:

TABLE_LIST::belong_to_derived is NULL if the table belongs to a
derived table that has non-MERGE type.
bb-10.5-MDEV-31477
Yuchen Pei 6 months ago
parent
commit
25f1e6f565
No known key found for this signature in database GPG Key ID: 3DD1B35105743563
  1. 2
      sql/table.h
  2. 3
      storage/spider/mysql-test/spider/bugfix/r/mdev_26345.result
  3. 1
      storage/spider/mysql-test/spider/bugfix/t/mdev_26345.test
  4. 4
      storage/spider/mysql-test/spider/bugfix/t/mdev_29502.test
  5. 10
      storage/spider/spd_group_by_handler.cc

2
sql/table.h

@ -2526,7 +2526,7 @@ struct TABLE_LIST
List<TABLE_LIST> *view_tables;
/* most upper view this table belongs to */
TABLE_LIST *belong_to_view;
/* A derived table this table belongs to */
/* A merged derived table this table belongs to */
TABLE_LIST *belong_to_derived;
/*
The view directly referencing this table

3
storage/spider/mysql-test/spider/bugfix/r/mdev_26345.result

@ -15,6 +15,9 @@ insert into t1 VALUES (1,4), (1,2), (2,11);
SELECT MIN(b), a FROM t1 WHERE a=1;
MIN(b) a
2 1
select * from (SELECT MIN(b), a FROM t1 WHERE a=1) as v;
MIN(b) a
2 1
SELECT MAX(b), a FROM t1 WHERE a<3;
MAX(b) a
11 1

1
storage/spider/mysql-test/spider/bugfix/t/mdev_26345.test

@ -22,6 +22,7 @@ create table t1 (a int, b int, PRIMARY KEY (a, b)) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
insert into t1 VALUES (1,4), (1,2), (2,11);
SELECT MIN(b), a FROM t1 WHERE a=1;
select * from (SELECT MIN(b), a FROM t1 WHERE a=1) as v;
SELECT MAX(b), a FROM t1 WHERE a<3;
drop table t1, t2;

4
storage/spider/mysql-test/spider/bugfix/t/mdev_29502.test

@ -24,10 +24,14 @@ eval CREATE TABLE t1 (a INT KEY) ENGINE=Spider COMMENT='WRAPPER "mysql",srv "$sr
SELECT MAX(a) FROM t1;
SELECT SUM(a) FROM t1;
SELECT COUNT(a) FROM t1;
# Spider does not create a GBH with view protocol in these cases which
# would cause extra direct aggregate counts than without view protocol
--disable_view_protocol
SELECT MAX(a), SUM(a) FROM t1;
SELECT COUNT(a), MAX(a), SUM(a) FROM t1;
SELECT MAX(a), COUNT(a), SUM(a) FROM t1;
SELECT MAX(a), MAX(COALESCE(a)) FROM t1;
--enable_view_protocol
SHOW STATUS LIKE 'Spider_direct_aggregate';
DROP TABLE t, t1;

10
storage/spider/spd_group_by_handler.cc

@ -1566,6 +1566,16 @@ group_by_handler *spider_create_group_by_handler(
DBUG_PRINT("info",("spider select item=%p", item));
if (item->const_item())
{
/*
Do not create the GBH when a derived table or view is
involved
*/
if (thd->derived_tables != NULL)
{
keep_going= FALSE;
break;
}
/*
Do not handle the complex case where there's a const item
in the auxiliary fields. It is too unlikely (if at all) to

Loading…
Cancel
Save