mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
MDEV-25202: JSON_TABLE: Early table reference leads to unexpected result set
(Also fixes MDEV-25254). Re-work Name Resolution for the argument of JSON_TABLE(json_doc, ....) function. The json_doc argument can refer to other tables, but it can only refer to the tables that precede[*] the JSON_TABLE(...) call. [*] - For queries with RIGHT JOINs, the "preceding" is determined after the query is normalized by converting RIGHT JOIN into left one. The implementation is as follows: - Table function arguments use their own Name_resolution_context. - The Name_resolution_context now has a bitmap of tables that should be ignored when searching for a field. - get_disallowed_table_deps() walks the TABLE_LIST::nested_join tree and computes a bitmap of tables that do not "precede" the given JSON_TABLE(...) invocation (according the above definition of "preceding").
This commit is contained in:
committed by
Alexey Botchkov
parent
13390a70e2
commit
84cf9c2e11
@@ -640,13 +640,13 @@ DEALLOCATE PREPARE stmt;
|
||||
CREATE TABLE t1 (id INT, jc JSON);
|
||||
SELECT * FROM t1 RIGHT JOIN JSON_TABLE(t1.jc, '$' COLUMNS
|
||||
(id FOR ORDINALITY)) as jt ON t1.jc=jt.id;
|
||||
id jc id
|
||||
ERROR 42S22: Unknown column 't1.jc' in 'JSON_TABLE argument'
|
||||
SELECT * FROM JSON_TABLE(t1.jc, '$' COLUMNS
|
||||
(id FOR ORDINALITY)) as jt LEFT JOIN t1 ON t1.jc=jt.id;
|
||||
ERROR 42S02: Unknown table 't1' in JSON_TABLE argument
|
||||
ERROR 42S22: Unknown column 't1.jc' in 'JSON_TABLE argument'
|
||||
SELECT * FROM JSON_TABLE(t1.jc, '$' COLUMNS
|
||||
(id FOR ORDINALITY)) as jt RIGHT JOIN t1 ON t1.jc=jt.id;
|
||||
ERROR 42S02: Unknown table 't1' in JSON_TABLE argument
|
||||
id id jc
|
||||
SELECT * FROM t1 LEFT JOIN JSON_TABLE(t1.jc, '$' COLUMNS
|
||||
(id FOR ORDINALITY)) as jt ON t1.jc=jt.id;
|
||||
id jc id
|
||||
@@ -667,34 +667,33 @@ SELECT * FROM t1 AS t1o RIGHT JOIN
|
||||
(t1 AS t1i JOIN JSON_TABLE(t1o.jc, '$' COLUMNS
|
||||
(id FOR ORDINALITY)) as jt ON t1i.jc=jt.id)
|
||||
ON t1o.id=t1i.id;
|
||||
id jc id jc id
|
||||
ERROR 42S22: Unknown column 't1o.jc' in 'JSON_TABLE argument'
|
||||
SELECT * FROM t1 AS t1o RIGHT JOIN
|
||||
(t1 AS t1i RIGHT JOIN JSON_TABLE(t1o.jc, '$' COLUMNS
|
||||
(id FOR ORDINALITY)) as jt ON t1i.jc=jt.id)
|
||||
ON t1o.id=t1i.id;
|
||||
id jc id jc id
|
||||
ERROR 42S22: Unknown column 't1o.jc' in 'JSON_TABLE argument'
|
||||
WITH qn AS
|
||||
(SELECT jt.* FROM t1 RIGHT JOIN JSON_TABLE(t1.jc, '$' COLUMNS
|
||||
(id FOR ORDINALITY)) as jt ON t1.jc=jt.id)
|
||||
SELECT * from qn;
|
||||
id
|
||||
ERROR 42S22: Unknown column 't1.jc' in 'JSON_TABLE argument'
|
||||
WITH qn AS
|
||||
(SELECT 1 UNION
|
||||
SELECT jt.id FROM t1 RIGHT JOIN JSON_TABLE(t1.jc, '$' COLUMNS
|
||||
(id FOR ORDINALITY)) as jt ON t1.jc=jt.id)
|
||||
SELECT * from qn;
|
||||
1
|
||||
1
|
||||
ERROR 42S22: Unknown column 't1.jc' in 'JSON_TABLE argument'
|
||||
SELECT * FROM t1 AS t1o RIGHT JOIN
|
||||
(t1 AS t1i JOIN JSON_TABLE(t1o.jc, '$' COLUMNS
|
||||
(id FOR ORDINALITY)) as jt ON t1i.jc=jt.id)
|
||||
ON t1o.id=t1i.id;
|
||||
id jc id jc id
|
||||
ERROR 42S22: Unknown column 't1o.jc' in 'JSON_TABLE argument'
|
||||
SELECT * FROM t1 AS t1o RIGHT JOIN
|
||||
(t1 AS t1i RIGHT JOIN JSON_TABLE(t1o.jc, '$' COLUMNS
|
||||
(id FOR ORDINALITY)) as jt ON t1i.jc=jt.id)
|
||||
ON t1o.id=t1i.id;
|
||||
id jc id jc id
|
||||
ERROR 42S22: Unknown column 't1o.jc' in 'JSON_TABLE argument'
|
||||
INSERT INTO t1 VALUES(1,"1"),(2,"4"),(3,"3");
|
||||
ANALYZE TABLE t1;
|
||||
Table Op Msg_type Msg_text
|
||||
@@ -717,7 +716,7 @@ LEFT JOIN
|
||||
JSON_TABLE(t1.jc, '$' COLUMNS (id FOR ORDINALITY)) as jt ON t1.jc=jt.id
|
||||
RIGHT JOIN
|
||||
JSON_TABLE(jt.id, '$' COLUMNS (id FOR ORDINALITY)) as jt1 ON jt.id=jt1.id;
|
||||
ERROR 42000: Cross dependency found in OUTER JOIN; examine your ON conditions
|
||||
ERROR 42S22: Unknown column 'jt.id' in 'JSON_TABLE argument'
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# Bug#25525409: ASSERTION `TABLE_LIST->TABLE' FAILED IN SQL/SQL_BASE.CC
|
||||
|
Reference in New Issue
Block a user