Commit 0f6e170c authored by Nayuta Yanagisawa's avatar Nayuta Yanagisawa

MDEV-25985 Spider handle ">=" as ">" in some cases

The function spider_db_append_key_where_internal() converts
HA_READ_AFTER_KEY to '>'. The conversion seems to be correct for
single-column indexes because HA_READ_AFTER_KEY means "read the
key after the provided value."

However, how about multi-column indexes? Assume that there is a
multi-column index on c1 and c2 and we search with the condition
'c1 >= 100 AND c2 > 200'. The key_range.flag corresponds to the
search condition could be HA_READ_AFTER_KEY. In such a case,
we could not simply convert HA_READ_AFTER_KEY to '>'.

The correct conversion is to convert HA_READ_AFTER_KEY to '>'
only for the last column in key_part_map and to convert
HA_READ_AFTER_KEY to '>=' for the other column.

The similar discussion also applies to the conversion from
key_range.flag to a sign of inequality.
parent 165a6dc9
......@@ -152,6 +152,11 @@ let $MASTER_1_COMMENT_TEXT_PK1_1=
COMMENT 'tbl "t1", srv "s_2_1"';
let $MASTER_1_COMMENT_TEXT_KEY1_1=
COMMENT 'tbl "t1", srv "s_2_1"';
let $MASTER_1_COMMENT_MDEV_25985=
COMMENT='table "t1"'
PARTITION BY LIST COLUMNS(`a`) (
PARTITION `pt1` DEFAULT COMMENT = 'srv "s_2_1"'
);
let $MASTER_1_CHECK_DIRECT_UPDATE_STATUS=
SHOW STATUS LIKE 'Spider_direct_update';
let $MASTER_1_CHECK_DIRECT_DELETE_STATUS=
......
......@@ -262,6 +262,40 @@ a b c d e f
56B68DA68D6D4A04A08B453D09AD7B70 821E71E6ABB4404EBAA349BB681089F8 51041110620310 2018-08-02 13:48:28 510411 0
51ECF2C0CD3C48D99C91792E99D3C1A0 017B8A460DBC444682B791305EF75356 51041110620308 2018-08-02 13:48:29 510411 0
093B37A93A534DF883787AF5F6799674 996C7F14989D480589A553717D735E3E 51041110620302 2018-08-02 13:48:30 510411 0
#
# MDEV-25985 Spider handle ">=" as ">" in some cases
#
connection child2_1;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (
a int,
b int,
c int,
PRIMARY KEY (a),
KEY (b,c)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO t1 VALUES (1, 1, 1), (2, 2, 1);
connection master_1;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (
a int,
b int,
c int,
PRIMARY KEY (a),
KEY (b,c)
) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "t1"'
PARTITION BY LIST COLUMNS(`a`) (
PARTITION `pt1` DEFAULT COMMENT = 'srv "s_2_1"'
);
connection master_1;
SELECT * FROM t1 WHERE c > 0 AND b >= 1 AND b <= 2;
a b c
1 1 1
2 2 1
SELECT * FROM t1 WHERE c < 3 AND b <= 2;
a b c
1 1 1
2 2 1
deinit
connection master_1;
......
......@@ -726,6 +726,41 @@ if ($HAVE_PARTITION)
}
}
--echo #
--echo # MDEV-25985 Spider handle ">=" as ">" in some cases
--echo #
--connection child2_1
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
eval CREATE TABLE t1 (
a int,
b int,
c int,
PRIMARY KEY (a),
KEY (b,c)
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
INSERT INTO t1 VALUES (1, 1, 1), (2, 2, 1);
--connection master_1
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
eval CREATE TABLE t1 (
a int,
b int,
c int,
PRIMARY KEY (a),
KEY (b,c)
) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_MDEV_25985;
--connection master_1
SELECT * FROM t1 WHERE c > 0 AND b >= 1 AND b <= 2;
SELECT * FROM t1 WHERE c < 3 AND b <= 2;
--echo
--echo deinit
--disable_warnings
......
......@@ -1867,12 +1867,20 @@ int spider_db_append_key_where_internal(
case HA_READ_AFTER_KEY:
if (sql_kind == SPIDER_SQL_KIND_SQL)
{
const char* op_str;
uint32 op_len;
if (start_key_part_map == 1) {
op_str = SPIDER_SQL_GT_STR;
op_len = SPIDER_SQL_GT_LEN;
} else {
op_str = SPIDER_SQL_GTEQUAL_STR;
op_len = SPIDER_SQL_GTEQUAL_LEN;
}
if (str->reserve(store_length + key_name_length +
/* SPIDER_SQL_NAME_QUOTE_LEN */ 2 +
SPIDER_SQL_GT_LEN))
/* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + op_len))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
dbton_share->append_column_name(str, field->field_index);
str->q_append(SPIDER_SQL_GT_STR, SPIDER_SQL_GT_LEN);
str->q_append(op_str, op_len);
if (spider_dbton[dbton_id].db_util->
append_column_value(spider, str, field, ptr,
share->access_charset))
......@@ -1927,12 +1935,20 @@ int spider_db_append_key_where_internal(
result_list->desc_flg = TRUE;
if (sql_kind == SPIDER_SQL_KIND_SQL)
{
const char* op_str;
uint32 op_len;
if (start_key_part_map == 1) {
op_str = SPIDER_SQL_LT_STR;
op_len = SPIDER_SQL_LT_LEN;
} else {
op_str = SPIDER_SQL_LTEQUAL_STR;
op_len = SPIDER_SQL_LTEQUAL_LEN;
}
if (str->reserve(store_length + key_name_length +
/* SPIDER_SQL_NAME_QUOTE_LEN */ 2 +
SPIDER_SQL_LT_LEN))
/* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + op_len))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
dbton_share->append_column_name(str, field->field_index);
str->q_append(SPIDER_SQL_LT_STR, SPIDER_SQL_LT_LEN);
str->q_append(op_str, op_len);
if (spider_dbton[dbton_id].db_util->
append_column_value(spider, str, field, ptr,
share->access_charset))
......@@ -2297,12 +2313,20 @@ int spider_db_append_key_where_internal(
case HA_READ_BEFORE_KEY:
if (sql_kind == SPIDER_SQL_KIND_SQL)
{
const char* op_str;
uint32 op_len;
if (end_key_part_map == 1) {
op_str = SPIDER_SQL_LT_STR;
op_len = SPIDER_SQL_LT_LEN;
} else {
op_str = SPIDER_SQL_LTEQUAL_STR;
op_len = SPIDER_SQL_LTEQUAL_LEN;
}
if (str->reserve(store_length + key_name_length +
/* SPIDER_SQL_NAME_QUOTE_LEN */ 2 +
SPIDER_SQL_LT_LEN))
/* SPIDER_SQL_NAME_QUOTE_LEN */ 2 + op_len))
DBUG_RETURN(HA_ERR_OUT_OF_MEM);
dbton_share->append_column_name(str, field->field_index);
str->q_append(SPIDER_SQL_LT_STR, SPIDER_SQL_LT_LEN);
str->q_append(op_str, op_len);
if (spider_dbton[dbton_id].db_util->
append_column_value(spider, str, field, ptr,
share->access_charset))
......
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