[MDEV-13399] Subquery returns multiple rows error when using column not marked as KEY Created: 2017-07-28  Updated: 2020-12-01

Status: Open
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 5.5, 10.0
Fix Version/s: 10.2

Type: Bug Priority: Major
Reporter: Vicențiu Ciorbaru Assignee: Vicențiu Ciorbaru
Resolution: Unresolved Votes: 0
Labels: None


 Description   

The following queries should return identical results, but they do not:

CREATE TABLE t1 (f1 INT, KEY(f1)) ENGINE=MyISAM;
INSERT t1 VALUES (4),(8);
CREATE TABLE t2 (f2 INT, KEY(f2)) ENGINE=MyISAM;
INSERT t2 VALUES (6),(9);
 
SELECT (SELECT MAX(t2.f2) FROM t1) FROM t2 WHERE f2 = 2;

This one returns NULL

While this one:

CREATE TABLE t1 (f1 INT) ENGINE=MyISAM;
INSERT t1 VALUES (4),(8);
CREATE TABLE t2 (f2 INT) ENGINE=MyISAM;
INSERT t2 VALUES (6),(9);
SELECT (SELECT MAX(t2.f2) FROM t1) FROM t2 WHERE f2 = 2;

Returns: Error: Subquery returns more than 1 row

This test case is from MDEV-7828 Assertion `key_read == 0' failed in TABLE::enable_keyread with SELECT SQ and WHERE SQ

10.0 behaves the same as the last example, with or without KEY being present.

  • NOTE * The query succeeds as 5.5 in 10.0 if subquery_cache=off is set.


 Comments   
Comment by Vicențiu Ciorbaru [ 2017-07-28 ]

CC: serg, sanja

Comment by Elena Stepanova [ 2017-10-17 ]

10.1 and 10.2 behave the same way as 10.0 – return the error for both cases.

So, which identical results should it be, NULL or the error?
If the error, then I guess it makes no sense to fix it in 5.5, since 10.x already do it.
In case it should return NULL, I'm setting the fix version to 10.1.

Generated at Thu Feb 08 08:05:18 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.