Commit 22cb0299 authored by Oleg Smirnov's avatar Oleg Smirnov

MDEV-34880 Incorrect result for query with derived table having TEXT field

When a derived table which has distinct values and BLOB fields is
materialized, an index is created over all columns to ensure only
distinct values are placed to the result.
This index is created in a special mode HA_UNIQUE_HASH to support BLOBs.
Later in `best_access_path` the optimizer may incorrectly choose this
index to retrieve values from the derived table, although such type
of index cannot be used for data retrieval.

This commit excludes HA_UNIQUE_HASH indexes from consideration
in `best_access_path`
parent f1b4d36c
......@@ -1862,3 +1862,15 @@ pk a
deallocate prepare stmt;
drop table t1,t2,t3;
# End of MariaDB 11.1 tests
#
# MDEV-34880: Incorrect result for query with derived table having TEXT field
#
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, notes TEXT NOT NULL);
INSERT INTO t1 VALUES (1, 'test1'), (2, 'test2');
SELECT dt.* FROM (SELECT * FROM t1 UNION SELECT * FROM t1) dt WHERE id = 1;
id notes
1 test1
DROP TABLE t1;
#
# End of 11.2 tests
#
......@@ -1511,3 +1511,17 @@ deallocate prepare stmt;
drop table t1,t2,t3;
--echo # End of MariaDB 11.1 tests
--echo #
--echo # MDEV-34880: Incorrect result for query with derived table having TEXT field
--echo #
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, notes TEXT NOT NULL);
INSERT INTO t1 VALUES (1, 'test1'), (2, 'test2');
SELECT dt.* FROM (SELECT * FROM t1 UNION SELECT * FROM t1) dt WHERE id = 1;
DROP TABLE t1;
--echo #
--echo # End of 11.2 tests
--echo #
......@@ -8942,8 +8942,11 @@ best_access_path(JOIN *join,
than a not unique key
Set tmp to the cost of the accessing the expected number of
records.
Exclude HA_UNIQUE_HASH indexes (1) since they cannot be used
for lookups
*/
if ((found_part & 1) &&
(!(table->key_info[key].flags & HA_UNIQUE_HASH)) && // (1)
(!(table->key_info[key].index_flags & HA_ONLY_WHOLE_INDEX) ||
found_part == PREV_BITS(uint,keyinfo->user_defined_key_parts)))
{
......@@ -9140,6 +9143,8 @@ best_access_path(JOIN *join,
{
if (!(found_part & 1))
cause= "no predicate for first keypart";
else if (table->key_info[key].flags & HA_UNIQUE_HASH)
cause= "key not usable for lookups (UNIQUE_HASH)";
else
cause= "No full key found";
trace_access_idx.add("chosen", false).add("cause", cause);
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