Commit a60d7b11 authored by Yuchen Pei's avatar Yuchen Pei

MDEV-26345 [wip] Skip "auxiliary" fields in spider group by handler

Also, stop skipping const items, which causes failures in mdev_29502
and mdev_20502
parent 0a5e4a01
......@@ -1473,7 +1473,7 @@ class JOIN :public Sql_alloc
Then, ORDER/GROUP BY and Window Function code add columns that need to
be saved to be available in the post-group-by context. These extra columns
are added to the front, because this->all_fields points to the suffix of
are added to the front, because this->fields_list points to the suffix of
this list.
*/
List<Item> all_fields;
......
for master_1
for child2
for child3
MDEV-26345 SELECT MIN on Spider table returns more rows than expected
set spider_same_server_link= 1;
CREATE SERVER srv FOREIGN DATA WRAPPER mysql
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
create table t2 (a int, b int, PRIMARY KEY (a, b));
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,1), (1,2), (2,11);
SELECT MIN(b), a FROM t1 WHERE a=1;
MIN(b) a
1 1
SELECT MAX(b), a FROM t1 WHERE a<3;
MAX(b) a
11 1
drop table t1, t2;
create table t2 (a int, b int);
create table t1 ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
insert into t1 VALUES (1,1), (1,1), (2,2), (2,2);
select distinct count(a) from t1 group by b;
count(a)
2
drop table t1, t2;
drop server srv;
for master_1
for child2
for child3
--disable_warnings
--disable_query_log
--disable_result_log
--source ../../t/test_init.inc
--enable_result_log
--enable_query_log
--enable_warnings
--echo
--echo MDEV-26345 SELECT MIN on Spider table returns more rows than expected
--echo
set spider_same_server_link= 1;
evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
create table t2 (a int, b int, PRIMARY KEY (a, b));
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,1), (1,2), (2,11);
SELECT MIN(b), a FROM t1 WHERE a=1;
SELECT MAX(b), a FROM t1 WHERE a<3;
drop table t1, t2;
create table t2 (a int, b int);
create table t1 ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
insert into t1 VALUES (1,1), (1,1), (2,2), (2,2);
select distinct count(a) from t1 group by b;
drop table t1, t2;
drop server srv;
--disable_warnings
--disable_query_log
--disable_result_log
--source ../../t/test_deinit.inc
--enable_result_log
--enable_query_log
--enable_warnings
......@@ -76,7 +76,7 @@ a b c
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
argument
select t0.`b` `b`,t0.`a` `a`,t2.`b` `b`,t2.`c` `c` from `auto_test_remote`.`ta_r` t0 join `auto_test_remote`.`ta_r_3` t1 join `auto_test_remote`.`ta_r_int` t2 where ((t0.`a` = t1.`a`) and (t2.`a` = t1.`a`)) order by t0.`b` desc limit 1,2
select 1,t0.`a` `a`,t2.`b` `b`,t2.`c` `c` from `auto_test_remote`.`ta_r` t0 join `auto_test_remote`.`ta_r_3` t1 join `auto_test_remote`.`ta_r_int` t2 where ((t0.`a` = t1.`a`) and (t2.`a` = t1.`a`)) order by t0.`b` desc limit 1,2
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a;
a b date_format(c, '%Y-%m-%d %H:%i:%s')
......
......@@ -79,7 +79,7 @@ a b c
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
argument
select t0.`b` `b`,t0.`a` `a`,t2.`b` `b`,t2.`c` `c` from `auto_test_remote`.`ta_r` t0 join `auto_test_remote`.`ta_r_3` t1 join `auto_test_remote`.`ta_r_int` t2 where ((t0.`a` = t1.`a`) and (t2.`a` = t1.`a`)) order by t0.`b` desc
select 1,t0.`a` `a`,t2.`b` `b`,t2.`c` `c` from `auto_test_remote`.`ta_r` t0 join `auto_test_remote`.`ta_r_3` t1 join `auto_test_remote`.`ta_r_int` t2 where ((t0.`a` = t1.`a`) and (t2.`a` = t1.`a`)) order by t0.`b` desc
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a;
a b date_format(c, '%Y-%m-%d %H:%i:%s')
......
......@@ -79,7 +79,7 @@ a b c
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
argument
select t0.`b` `b`,t0.`a` `a`,t2.`b` `b`,t2.`c` `c` from `auto_test_remote`.`ta_r` t0 left join `auto_test_remote`.`ta_r_3` t1 on (t1.`a` = t0.`a`) left join `auto_test_remote`.`ta_r_int` t2 on (t2.`a` = t0.`a`) where 1 order by t0.`b` desc
select 1,t0.`a` `a`,t2.`b` `b`,t2.`c` `c` from `auto_test_remote`.`ta_r` t0 left join `auto_test_remote`.`ta_r_3` t1 on (t1.`a` = t0.`a`) left join `auto_test_remote`.`ta_r_int` t2 on (t2.`a` = t0.`a`) where 1 order by t0.`b` desc
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a;
a b date_format(c, '%Y-%m-%d %H:%i:%s')
......
......@@ -79,7 +79,7 @@ a b c
connection child2_1;
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
argument
select t0.`b` `b`,t0.`a` `a`,t2.`b` `b`,t2.`c` `c` from `auto_test_remote`.`ta_r_int` t2 left join (`auto_test_remote`.`ta_r_3` t1 join `auto_test_remote`.`ta_r` t0) on ((t0.`a` = t2.`a`) and (t1.`a` = t2.`a`)) where 1 order by t0.`b` desc
select 1,t0.`a` `a`,t2.`b` `b`,t2.`c` `c` from `auto_test_remote`.`ta_r_int` t2 left join (`auto_test_remote`.`ta_r_3` t1 join `auto_test_remote`.`ta_r` t0) on ((t0.`a` = t2.`a`) and (t1.`a` = t2.`a`)) where 1 order by t0.`b` desc
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r ORDER BY a;
a b date_format(c, '%Y-%m-%d %H:%i:%s')
......
......@@ -13971,14 +13971,19 @@ int spider_mbase_handler::append_list_item_select(
Item *item;
Field *field;
const char *item_name;
uint skip= select->elements - fields->get_first_table_holder()->table->pos_in_table_list->select_lex->join->fields_list.elements;
DBUG_ENTER("spider_mbase_handler::append_list_item_select");
DBUG_PRINT("info",("spider this=%p", this));
begin = str->length();
while ((item = it++))
{
if (item->const_item())
if (skip > 0)
{
DBUG_PRINT("info",("spider const item"));
str->reserve(2);
str->q_append("1", 1);
field = *(fields->get_next_field_ptr());
str->q_append(SPIDER_SQL_COMMA_STR, SPIDER_SQL_COMMA_LEN);
skip--;
continue;
}
if ((error_num = spider_db_print_item_type(item, NULL, spider, str,
......
......@@ -12460,11 +12460,6 @@ int spider_oracle_handler::append_list_item_select(
begin = str->length();
while ((item = it++))
{
if (item->const_item())
{
DBUG_PRINT("info",("spider const item"));
continue;
}
if ((error_num = spider_db_print_item_type(item, NULL, spider, str,
alias, alias_length, dbton_id, use_fields, fields)))
{
......
......@@ -1547,11 +1547,6 @@ group_by_handler *spider_create_group_by_handler(
while ((item = it++))
{
DBUG_PRINT("info",("spider select item=%p", item));
if (item->const_item())
{
DBUG_PRINT("info",("spider const item"));
continue;
}
if (spider_db_print_item_type(item, NULL, spider, NULL, NULL, 0,
roop_count, TRUE, fields_arg))
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment