Failed tests in the 001 suite in 1.4 (MCOL-3594)

[MCOL-3757] CS does not support LIMIT in correlated subqueries, but gives erroneous results Created: 2020-02-04  Updated: 2020-05-07  Resolved: 2020-05-07

Status: Closed
Project: MariaDB ColumnStore
Component/s: MDB Plugin
Affects Version/s: 1.4.3
Fix Version/s: 1.4.4

Type: Sub-Task Priority: Minor
Reporter: Roman Assignee: Daniel Lee (Inactive)
Resolution: Fixed Votes: 1
Labels: None

Sprint: 2020-1, 2020-2, 2020-3, 2020-4, 2020-5, 2020-6, 2020-7

 Description   

CS previously returned an error for some queries that failed previously:

SELECT DISTINCT t2.gid AS lgid,
                (SELECT t1.name FROM t1, t2
                   WHERE t1.lid  = t2.lid AND t2.gid = lgid
                     ORDER BY t2.dt DESC LIMIT 1
                ) as clid
  FROM t2;
 
CREATE VIEW v1 AS
SELECT DISTINCT t2.gid AS lgid,
                (SELECT t1.name FROM t1, t2
                   WHERE t1.lid  = t2.lid AND t2.gid = lgid
                     ORDER BY t2.dt DESC LIMIT 1
                ) as clid
  FROM t2;
SELECT * FROM v1;
 
-ERROR 1815 (HY000) at line 96: Internal error: IDB-3019: Limit within a correlated subquery is currently not supported.
-ERROR 1815 (HY000) at line 110: Internal error: IDB-3019: Limit within a correlated subquery is currently not supported.

Now these queries work. We need to investigate the scope of this unexpected free feature.



 Comments   
Comment by David Hall (Inactive) [ 2020-02-27 ]

In 1.2, we had

        if (csep->limitNum() != (uint64_t) - 1 &&
                gwi.subQuery && !gwi.correlatedTbNameVec.empty())

In 1.4, we have

        if (gwi.subQuery && !gwi.correlatedTbNameVec.empty() && csep->hasOrderBy())

This was changed in MCOL-2178 'Fix for handlers fallback mechanism patch'
However, csep->hasOrderBy() is never set for subquery, so the error is never detected.

I commented out the error detection code in 1.2 and the query succeeded, so it appears the system has supported at least this one example of a limit in a subquery for a while.

Comment by Roman [ 2020-03-01 ]

Does it really returns expected results?

Comment by David Hall (Inactive) [ 2020-03-05 ]

The result set returned is incorrect. We must re-enable the error message.

Comment by David Hall (Inactive) [ 2020-04-20 ]

I had submitted, as part of MCOL-3594, changes to support the new behavior. Since the new behavior is incorrect and has been reverted, I also reverted the changes in the Pull Request for MCOL-3594

Comment by David Hall (Inactive) [ 2020-05-07 ]

DDL and DML for example:

CREATE TABLE t1 (lid int, name char(10)) engine=columnstore;
INSERT INTO t1 (lid, name) VALUES (1, 'YES'), (2, 'NO');

CREATE TABLE t2 ( id int, gid int, lid int, dt date) engine=columnstore;
INSERT INTO t2 (id, gid, lid, dt) VALUES
(1, 1, 1, '2007-01-01'),(2, 1, 2, '2007-01-02'),
(3, 2, 2, '2007-02-01'),(4, 2, 1, '2007-02-02');

Comment by Daniel Lee (Inactive) [ 2020-05-07 ]

Build verified: 1.4.4-1, Jenkins-20200506

The fix is to restore the error checking and return a messages for non-support syntax

Server version: 10.4.12-6-MariaDB-enterprise MariaDB Enterprise Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [mytest]> CREATE TABLE t1 (lid int, name char(10)) engine=columnstore;
Query OK, 0 rows affected (0.219 sec)

MariaDB [mytest]> INSERT INTO t1 (lid, name) VALUES (1, 'YES'), (2, 'NO');
Query OK, 2 rows affected (1.334 sec)
Records: 2 Duplicates: 0 Warnings: 0

MariaDB [mytest]> CREATE TABLE t2 ( id int, gid int, lid int, dt date) engine=columnstore;
Query OK, 0 rows affected (0.181 sec)

MariaDB [mytest]> INSERT INTO t2 (id, gid, lid, dt) VALUES
-> (1, 1, 1, '2007-01-01'),(2, 1, 2, '2007-01-02'),
-> (3, 2, 2, '2007-02-01'),(4, 2, 1, '2007-02-02');
Query OK, 4 rows affected (0.456 sec)
Records: 4 Duplicates: 0 Warnings: 0

MariaDB [mytest]> SELECT DISTINCT t2.gid AS lgid,
-> (SELECT t1.name FROM t1, t2
-> WHERE t1.lid = t2.lid AND t2.gid = lgid
-> ORDER BY t2.dt DESC LIMIT 1
-> ) as clid
-> FROM t2;
ERROR 1815 (HY000): Internal error: IDB-3019: Limit within a correlated subquery is currently not supported.
MariaDB [mytest]> CREATE VIEW v1 AS
-> SELECT DISTINCT t2.gid AS lgid,
-> (SELECT t1.name FROM t1, t2
-> WHERE t1.lid = t2.lid AND t2.gid = lgid
-> ORDER BY t2.dt DESC LIMIT 1
-> ) as clid
-> FROM t2;
Query OK, 0 rows affected (0.001 sec)

MariaDB [mytest]> SELECT * FROM v1;
ERROR 1815 (HY000): Internal error: IDB-3019: Limit within a correlated subquery is currently not supported.

Generated at Thu Feb 08 02:45:12 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.