Skip to content

Commit eb2ca3d

Browse files
author
Jacob Mathew
committed
MDEV-16912: Spider Order By column[datatime] limit 5 returns 3 rows
The problem occurs in 10.2 and earlier releases of MariaDB Server because the Partition Engine was not pushing the engine conditions to the underlying storage engine of each partition. This caused Spider to return the first 5 rows in the table with the data provided by the customer. 2 of the 5 rows did not qualify the WHERE clause, so they were removed from the result set by the server. To fix the problem, I have back-ported support for engine condition pushdown in the Partition Engine from MariaDB Server 10.3. Author: Jacob Mathew. Reviewer: Kentoku Shiba.
1 parent e76c4c0 commit eb2ca3d

File tree

6 files changed

+234
-0
lines changed

6 files changed

+234
-0
lines changed

sql/ha_partition.cc

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9130,6 +9130,56 @@ int ha_partition::check_for_upgrade(HA_CHECK_OPT *check_opt)
91309130
}
91319131

91329132

9133+
/**
9134+
Push an engine condition to the condition stack of the storage engine
9135+
for each partition.
9136+
9137+
@param cond Pointer to the engine condition to be pushed.
9138+
9139+
@return NULL Underlying engine will not return rows that
9140+
do not match the passed condition.
9141+
<> NULL 'Remainder' condition that the caller must use
9142+
to filter out records.
9143+
*/
9144+
9145+
const COND *ha_partition::cond_push(const COND *cond)
9146+
{
9147+
handler **file= m_file;
9148+
COND *res_cond= NULL;
9149+
DBUG_ENTER("ha_partition::cond_push");
9150+
9151+
do
9152+
{
9153+
if ((*file)->pushed_cond != cond)
9154+
{
9155+
if ((*file)->cond_push(cond))
9156+
res_cond= (COND *) cond;
9157+
else
9158+
(*file)->pushed_cond= cond;
9159+
}
9160+
} while (*(++file));
9161+
DBUG_RETURN(res_cond);
9162+
}
9163+
9164+
9165+
/**
9166+
Pop the top condition from the condition stack of the storage engine
9167+
for each partition.
9168+
*/
9169+
9170+
void ha_partition::cond_pop()
9171+
{
9172+
handler **file= m_file;
9173+
DBUG_ENTER("ha_partition::cond_pop");
9174+
9175+
do
9176+
{
9177+
(*file)->cond_pop();
9178+
} while (*(++file));
9179+
DBUG_VOID_RETURN;
9180+
}
9181+
9182+
91339183
struct st_mysql_storage_engine partition_storage_engine=
91349184
{ MYSQL_HANDLERTON_INTERFACE_VERSION };
91359185

sql/ha_partition.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,14 @@ class ha_partition :public handler
12001200
virtual bool is_crashed() const;
12011201
virtual int check_for_upgrade(HA_CHECK_OPT *check_opt);
12021202

1203+
/*
1204+
-----------------------------------------------------------------------
1205+
MODULE condition pushdown
1206+
-----------------------------------------------------------------------
1207+
*/
1208+
virtual const COND *cond_push(const COND *cond);
1209+
virtual void cond_pop();
1210+
12031211
private:
12041212
int handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt, uint flags);
12051213
int handle_opt_part(THD *thd, HA_CHECK_OPT *check_opt, uint part_id,

storage/spider/mysql-test/spider/include/init_child2_1.inc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ let $CHILD2_1_CREATE_TABLES6=
6969
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
7070
let $CHILD2_1_SELECT_TABLES6=
7171
SELECT a, b, date_format(c, '%Y-%m-%d %H:%i:%s') FROM ta_r_3 ORDER BY a;
72+
let $CHILD2_1_DROP_TABLES7=
73+
DROP TABLE IF EXISTS ta_ob;
74+
let $CHILD2_1_CREATE_TABLES7=
75+
CREATE TABLE ta_ob (
76+
a VARCHAR(50) NOT NULL,
77+
b VARCHAR(50) NULL DEFAULT NULL,
78+
c VARCHAR(100) NULL DEFAULT NULL,
79+
d DATETIME(0) NULL DEFAULT NULL,
80+
e INT(11) NOT NULL,
81+
f INT(10) NULL DEFAULT NULL,
82+
PRIMARY KEY (a, e)
83+
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
84+
let $CHILD2_1_SELECT_TABLES7=
85+
SELECT * FROM ta_ob WHERE c LIKE "%510411106%" AND e = 510411 AND f != 1 ORDER BY d,c LIMIT 6 OFFSET 0;
7286
let $CHILD2_1_DROP_FT_TABLES=
7387
DROP TABLE IF EXISTS ft_r;
7488
let $CHILD2_1_CREATE_FT_TABLES=

storage/spider/mysql-test/spider/include/init_master_1.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ if (!$VERSION_COMPILE_OS_WIN)
9494
CONNECTION='host "localhost", socket "$CHILD2_1_MYSOCK", user "root",
9595
password ""';
9696
}
97+
let $MASTER_1_COMMENT6_P_1_1=
98+
COMMENT='database "auto_test_remote", table "ta_ob"'
99+
PARTITION BY LIST COLUMNS (e) PARTITIONS 1
100+
(PARTITION pt1 values in (510411) COMMENT = 'srv "s_2_1"');
97101
if ($VERSION_COMPILE_OS_WIN)
98102
{
99103
let $MASTER_1_COMMENT_FT_2_1=

storage/spider/mysql-test/spider/r/spider_fixes_part.result

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,55 @@ id
214214
10000
215215
connection master_1;
216216

217+
Test ORDER BY with LIMIT and OFFSET
218+
connection master_1;
219+
CREATE TABLE ta_ob (
220+
a VARCHAR(50) NOT NULL,
221+
b VARCHAR(50) NULL DEFAULT NULL,
222+
c VARCHAR(100) NULL DEFAULT NULL,
223+
d DATETIME(0) NULL DEFAULT NULL,
224+
e INT(11) NOT NULL,
225+
f INT(10) NULL DEFAULT NULL,
226+
PRIMARY KEY (a, e)
227+
) ENGINE=Spider COMMENT='database "auto_test_remote", table "ta_ob"'
228+
PARTITION BY LIST COLUMNS (e) PARTITIONS 1
229+
(PARTITION pt1 values in (510411) COMMENT = 'srv "s_2_1"')
230+
INSERT INTO ta_ob VALUES ('0B95CD65DF994BC9A09A6AABE53A2733',
231+
'6CFED89FF6A84C7AA55C3C432663D094',
232+
'51041110620304', '2018-08-02 13:41:13',
233+
510411, 1);
234+
INSERT INTO ta_ob VALUES ('15E8D55EF099443BAEE639E60A4650BD',
235+
'879DC2A0B6AC46D9A62E8EA47E2970F2',
236+
'51041110620301', NULL,
237+
510411, 0);
238+
INSERT INTO ta_ob VALUES ('51ECF2C0CD3C48D99C91792E99D3C1A0',
239+
'017B8A460DBC444682B791305EF75356',
240+
'51041110620308', '2018-08-02 13:48:29',
241+
510411, 0);
242+
INSERT INTO ta_ob VALUES ('093B37A93A534DF883787AF5F6799674',
243+
'996C7F14989D480589A553717D735E3E',
244+
'51041110620302', '2018-08-02 13:48:30',
245+
510411, 0);
246+
INSERT INTO ta_ob VALUES ('53F5266FB069499AB6234755CACA2583',
247+
'017B8A460DBC444682B791305EF75356',
248+
'51041110620308', '2018-08-02 13:48:28',
249+
510411, 0);
250+
INSERT INTO ta_ob VALUES ('56E59BC4BDC143868D4A219C2D07A24B',
251+
'821E71E6ABB4404EBAA349BB681089F8',
252+
'51041110620310', '2018-08-02 13:48:27',
253+
510411, 0);
254+
INSERT INTO ta_ob VALUES ('56B68DA68D6D4A04A08B453D09AD7B70',
255+
'821E71E6ABB4404EBAA349BB681089F8',
256+
'51041110620310', '2018-08-02 13:48:28',
257+
510411, 0);
258+
SELECT * FROM ta_ob WHERE c LIKE "%510411106%" AND e = 510411 AND f != 1 ORDER BY d,c LIMIT 5 OFFSET 1;
259+
a b c d e f
260+
56E59BC4BDC143868D4A219C2D07A24B 821E71E6ABB4404EBAA349BB681089F8 51041110620310 2018-08-02 13:48:27 510411 0
261+
53F5266FB069499AB6234755CACA2583 017B8A460DBC444682B791305EF75356 51041110620308 2018-08-02 13:48:28 510411 0
262+
56B68DA68D6D4A04A08B453D09AD7B70 821E71E6ABB4404EBAA349BB681089F8 51041110620310 2018-08-02 13:48:28 510411 0
263+
51ECF2C0CD3C48D99C91792E99D3C1A0 017B8A460DBC444682B791305EF75356 51041110620308 2018-08-02 13:48:29 510411 0
264+
093B37A93A534DF883787AF5F6799674 996C7F14989D480589A553717D735E3E 51041110620302 2018-08-02 13:48:30 510411 0
265+
217266
deinit
218267
connection master_1;
219268
DROP DATABASE IF EXISTS auto_test_local;

storage/spider/mysql-test/spider/t/spider_fixes_part.test

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,115 @@ if ($HAVE_PARTITION)
616616
}
617617
}
618618

619+
--echo
620+
--echo Test ORDER BY with LIMIT and OFFSET
621+
if ($HAVE_PARTITION)
622+
{
623+
if ($USE_CHILD_GROUP2)
624+
{
625+
if (!$OUTPUT_CHILD_GROUP2)
626+
{
627+
--disable_query_log
628+
--disable_result_log
629+
}
630+
--connection child2_1
631+
if ($OUTPUT_CHILD_GROUP2)
632+
{
633+
--disable_query_log
634+
echo CHILD2_1_DROP_TABLES7;
635+
echo CHILD2_1_CREATE_TABLES7;
636+
}
637+
--disable_warnings
638+
eval $CHILD2_1_DROP_TABLES7;
639+
--enable_warnings
640+
eval $CHILD2_1_CREATE_TABLES7;
641+
if ($OUTPUT_CHILD_GROUP2)
642+
{
643+
--enable_query_log
644+
}
645+
if ($USE_GENERAL_LOG)
646+
{
647+
TRUNCATE TABLE mysql.general_log;
648+
}
649+
if (!$OUTPUT_CHILD_GROUP2)
650+
{
651+
--enable_query_log
652+
--enable_result_log
653+
}
654+
}
655+
--connection master_1
656+
--disable_query_log
657+
--disable_warnings
658+
DROP TABLE IF EXISTS ta_ob;
659+
--enable_warnings
660+
echo CREATE TABLE ta_ob (
661+
a VARCHAR(50) NOT NULL,
662+
b VARCHAR(50) NULL DEFAULT NULL,
663+
c VARCHAR(100) NULL DEFAULT NULL,
664+
d DATETIME(0) NULL DEFAULT NULL,
665+
e INT(11) NOT NULL,
666+
f INT(10) NULL DEFAULT NULL,
667+
PRIMARY KEY (a, e)
668+
) $MASTER_1_ENGINE $MASTER_1_COMMENT6_P_1_1;
669+
eval CREATE TABLE ta_ob (
670+
a VARCHAR(50) NOT NULL,
671+
b VARCHAR(50) NULL DEFAULT NULL,
672+
c VARCHAR(100) NULL DEFAULT NULL,
673+
d DATETIME(0) NULL DEFAULT NULL,
674+
e INT(11) NOT NULL,
675+
f INT(10) NULL DEFAULT NULL,
676+
PRIMARY KEY (a, e)
677+
) $MASTER_1_ENGINE $MASTER_1_COMMENT6_P_1_1;
678+
--enable_query_log
679+
INSERT INTO ta_ob VALUES ('0B95CD65DF994BC9A09A6AABE53A2733',
680+
'6CFED89FF6A84C7AA55C3C432663D094',
681+
'51041110620304', '2018-08-02 13:41:13',
682+
510411, 1);
683+
INSERT INTO ta_ob VALUES ('15E8D55EF099443BAEE639E60A4650BD',
684+
'879DC2A0B6AC46D9A62E8EA47E2970F2',
685+
'51041110620301', NULL,
686+
510411, 0);
687+
INSERT INTO ta_ob VALUES ('51ECF2C0CD3C48D99C91792E99D3C1A0',
688+
'017B8A460DBC444682B791305EF75356',
689+
'51041110620308', '2018-08-02 13:48:29',
690+
510411, 0);
691+
INSERT INTO ta_ob VALUES ('093B37A93A534DF883787AF5F6799674',
692+
'996C7F14989D480589A553717D735E3E',
693+
'51041110620302', '2018-08-02 13:48:30',
694+
510411, 0);
695+
INSERT INTO ta_ob VALUES ('53F5266FB069499AB6234755CACA2583',
696+
'017B8A460DBC444682B791305EF75356',
697+
'51041110620308', '2018-08-02 13:48:28',
698+
510411, 0);
699+
INSERT INTO ta_ob VALUES ('56E59BC4BDC143868D4A219C2D07A24B',
700+
'821E71E6ABB4404EBAA349BB681089F8',
701+
'51041110620310', '2018-08-02 13:48:27',
702+
510411, 0);
703+
INSERT INTO ta_ob VALUES ('56B68DA68D6D4A04A08B453D09AD7B70',
704+
'821E71E6ABB4404EBAA349BB681089F8',
705+
'51041110620310', '2018-08-02 13:48:28',
706+
510411, 0);
707+
SELECT * FROM ta_ob WHERE c LIKE "%510411106%" AND e = 510411 AND f != 1 ORDER BY d,c LIMIT 5 OFFSET 1;
708+
if ($USE_CHILD_GROUP2)
709+
{
710+
if (!$OUTPUT_CHILD_GROUP2)
711+
{
712+
--disable_query_log
713+
--disable_result_log
714+
}
715+
--connection child2_1
716+
if ($USE_GENERAL_LOG)
717+
{
718+
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
719+
}
720+
eval $CHILD2_1_SELECT_TABLES7;
721+
if (!$OUTPUT_CHILD_GROUP2)
722+
{
723+
--enable_query_log
724+
--enable_result_log
725+
}
726+
}
727+
}
619728

620729
--echo
621730
--echo deinit

0 commit comments

Comments
 (0)