Commit a6254e5e authored by Sergei Petrunia's avatar Sergei Petrunia

MDEV-14563: Wrong query plan for query with no PK

TABLE_SHARE::init_from_binary_frm_image() calls handler_file->index_flags()
before it has set TABLE_SHARE::primary_key (it is 0 while it should be
MAX_KEY in my example).
This causes MyRocks to report wrong index flags (it thinks it's a PK while
it is not), which causes invalid query plans later on.

Do the only thing that seems feasible: adjust field->part_of key to have
correct value in ha_rocksdb::open.
parent c3803914
...@@ -5717,6 +5717,18 @@ int ha_rocksdb::open(const char *const name, int mode, uint test_if_locked) { ...@@ -5717,6 +5717,18 @@ int ha_rocksdb::open(const char *const name, int mode, uint test_if_locked) {
} }
} }
} }
for (uint key= 0; key < table->s->keys; key++) {
KEY *const key_info = &table->key_info[key];
for (uint kp = 0; kp < key_info->usable_key_parts; kp++) {
uint field_index= key_info->key_part[kp].field->field_index;
if (m_key_descr_arr[key]->can_unpack(kp)) {
table->field[field_index]->part_of_key.set_bit(key);
} else {
table->field[field_index]->part_of_key.clear_bit(key);
}
}
}
} }
info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST); info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
......
...@@ -30,4 +30,28 @@ a b c d e ...@@ -30,4 +30,28 @@ a b c d e
2 1 1 1 0 2 1 1 1 0
3 1 1 1 0 3 1 1 1 0
DROP TABLE t1; DROP TABLE t1;
#
# MDEV-14563: Wrong query plan for query with no PK
#
CREATE TABLE t1(
pk int primary key,
a varchar(10) NOT NULL,
e int(11) DEFAULT 0,
KEY (a)
) ENGINE=ROCKSDB DEFAULT CHARSET=utf8;
insert into t1 values (1,1,1),(2,2,2);
explain select a from t1 where a <'zzz';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range a a 32 NULL # Using where
CREATE TABLE t2(
pk int,
a varchar(10) NOT NULL,
e int(11) DEFAULT 0,
KEY (a)
) ENGINE=ROCKSDB DEFAULT CHARSET=utf8;
insert into t2 values (1,1,1),(2,2,2);
explain select a from t2 where a <'zzz';
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 range a a 32 NULL # Using where
drop table t1,t2;
set global rocksdb_strict_collation_check=@tmp_rscc; set global rocksdb_strict_collation_check=@tmp_rscc;
...@@ -27,4 +27,30 @@ select a from t1; ...@@ -27,4 +27,30 @@ select a from t1;
select * from t1; select * from t1;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # MDEV-14563: Wrong query plan for query with no PK
--echo #
CREATE TABLE t1(
pk int primary key,
a varchar(10) NOT NULL,
e int(11) DEFAULT 0,
KEY (a)
) ENGINE=ROCKSDB DEFAULT CHARSET=utf8;
insert into t1 values (1,1,1),(2,2,2);
--replace_column 9 #
explain select a from t1 where a <'zzz';
CREATE TABLE t2(
pk int,
a varchar(10) NOT NULL,
e int(11) DEFAULT 0,
KEY (a)
) ENGINE=ROCKSDB DEFAULT CHARSET=utf8;
insert into t2 values (1,1,1),(2,2,2);
--replace_column 9 #
explain select a from t2 where a <'zzz';
drop table t1,t2;
set global rocksdb_strict_collation_check=@tmp_rscc; set global rocksdb_strict_collation_check=@tmp_rscc;
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