Skip to content

Commit 4194f7b

Browse files
MDEV-25116 Spider: IF(COUNT( trigger SQL Error (1054)_ Unknown column '' in field list
The original query "SELECT IF(COUNT(a.`id`)>=0,'Y','N') FROM t" is transformed to "SELECT COUNT(a.`id`), IF(ref >= 0, 'Y', 'N') FROM t", where ref is Item_ref to "COUNT(a.`id`)", by split_sum_func(). Spider walks the item list twice, invoking spider_db_print_item_type(). The first invocation is in spider_create_group_by_handler() with str == NULL. The second one is in spider_group_by_handler::init_scan() with str != NULL. spider_db_print_item_type() prints nothing at the first invocation, and it prints item at the second invocation. However, at the second invocation, the above mentioned ref to "COUNT(a.`id`)" points to a field in a temporary table where the result will be stored. Thus, to look behind the item_ref, Spider need to generate the query earlier. A possible fix would be to generate a query to send in spider_create_group_by_handler(). However, the fix requires a considerable amount of changes of the Spider's GROUP BY handler. I'd like to avoid that. So, I fix the problem by not to use the GROUP BY handler when a query contains Item_ref whose table_name, name, and alias_name_used are not set.
1 parent b725a91 commit 4194f7b

File tree

4 files changed

+74
-2
lines changed

4 files changed

+74
-2
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
# MDEV-25116 Spider: IF(COUNT( trigger SQL Error (1054)_ Unknown column '' in field list
3+
#
4+
for master_1
5+
for child2
6+
child2_1
7+
child2_2
8+
child2_3
9+
for child3
10+
connection child2_1;
11+
CREATE DATABASE auto_test_remote;
12+
USE auto_test_remote;
13+
CREATE TABLE tbl_a (id INT);
14+
connection master_1;
15+
CREATE DATABASE auto_test_local;
16+
USE auto_test_local;
17+
CREATE TABLE tbl_a (
18+
id INT
19+
) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a", srv "s_2_1"';
20+
connection master_1;
21+
SELECT IF(COUNT(id > 0),'Y','N') FROM tbl_a;
22+
IF(COUNT(id > 0),'Y','N')
23+
N
24+
connection master_1;
25+
DROP DATABASE IF EXISTS auto_test_local;
26+
connection child2_1;
27+
DROP DATABASE IF EXISTS auto_test_remote;
28+
for master_1
29+
for child2
30+
child2_1
31+
child2_2
32+
child2_3
33+
for child3
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
!include include/default_mysqld.cnf
2+
!include ../my_1_1.cnf
3+
!include ../my_2_1.cnf
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--echo #
2+
--echo # MDEV-25116 Spider: IF(COUNT( trigger SQL Error (1054)_ Unknown column '' in field list
3+
--echo #
4+
5+
--disable_query_log
6+
--disable_result_log
7+
--source ../../t/test_init.inc
8+
--enable_result_log
9+
--enable_query_log
10+
11+
--connection child2_1
12+
CREATE DATABASE auto_test_remote;
13+
USE auto_test_remote;
14+
15+
CREATE TABLE tbl_a (id INT);
16+
17+
--connection master_1
18+
CREATE DATABASE auto_test_local;
19+
USE auto_test_local;
20+
21+
eval CREATE TABLE tbl_a (
22+
id INT
23+
) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a", srv "s_2_1"';
24+
25+
--connection master_1
26+
SELECT IF(COUNT(id > 0),'Y','N') FROM tbl_a;
27+
28+
--connection master_1
29+
DROP DATABASE IF EXISTS auto_test_local;
30+
--connection child2_1
31+
DROP DATABASE IF EXISTS auto_test_remote;
32+
33+
--disable_query_log
34+
--disable_result_log
35+
--source ../t/test_deinit.inc
36+
--enable_query_log
37+
--enable_result_log

storage/spider/spd_db_conn.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9298,8 +9298,7 @@ int spider_db_open_item_ref(
92989298
}
92999299
DBUG_RETURN(0);
93009300
}
9301-
DBUG_RETURN(spider_db_print_item_type(*(item_ref->ref), NULL, spider, str,
9302-
alias, alias_length, dbton_id, use_fields, fields));
9301+
DBUG_RETURN(ER_SPIDER_COND_SKIP_NUM); // MDEV-25116
93039302
}
93049303
DBUG_RETURN(spider_db_open_item_ident((Item_ident *) item_ref, spider, str,
93059304
alias, alias_length, dbton_id, use_fields, fields));

0 commit comments

Comments
 (0)