mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
Bug #25831: Deficiencies in INSERT ... SELECT ... field name resolving.
Several problems fixed: 1. There was a "catch-all" context initialization in setup_tables() that was causing the table that we insert into to be visible in the SELECT part of an INSERT .. SELECT .. statement with no tables in its FROM clause. This was making sure all the under-initialized contexts in various parts of the code are not left uninitialized. Fixed by removing the "catch-all" statement and initializing the context in the parser. 2. Incomplete name resolution context when resolving the right-hand values in the ON DUPLICATE KEY UPDATE ... part of an INSERT ... SELECT ... caused columns from NATURAL JOIN/JOIN USING table references in the FROM clause of the select to be unavailable. Fixed by establishing a proper name resolution context. 3. When setting up the special name resolution context for problem 2 there was no check for cases where an aggregate function without a GROUP BY effectively takes the column from the SELECT part of an INSERT ... SELECT unavailable for ON DUPLICATE KEY UPDATE. Fixed by checking for that condition when setting up the name resolution context.
This commit is contained in:
@ -219,3 +219,20 @@ SELECT * FROM t1;
|
||||
a b
|
||||
45 2
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
|
||||
INSERT INTO t1 SELECT 1, j;
|
||||
ERROR 42S22: Unknown column 'j' in 'field list'
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
|
||||
CREATE TABLE t2 (a INT, b INT);
|
||||
CREATE TABLE t3 (a INT, c INT);
|
||||
INSERT INTO t1 SELECT 1, a FROM t2 NATURAL JOIN t3
|
||||
ON DUPLICATE KEY UPDATE j= a;
|
||||
DROP TABLE t1,t2,t3;
|
||||
CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
|
||||
CREATE TABLE t2 (a INT);
|
||||
INSERT INTO t1 VALUES (1, 1);
|
||||
INSERT INTO t2 VALUES (1), (3);
|
||||
INSERT INTO t1 SELECT 1, COUNT(*) FROM t2 ON DUPLICATE KEY UPDATE j= a;
|
||||
ERROR 42S22: Unknown column 'a' in 'field list'
|
||||
DROP TABLE t1,t2;
|
||||
|
@ -139,3 +139,26 @@ INSERT INTO t1 VALUES (45, 1) ON DUPLICATE KEY UPDATE b =
|
||||
SELECT * FROM t1;
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
#
|
||||
# Bug#25831: Deficiencies in INSERT ... SELECT ... field name resolving.
|
||||
#
|
||||
CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
|
||||
--error ER_BAD_FIELD_ERROR
|
||||
INSERT INTO t1 SELECT 1, j;
|
||||
DROP TABLE t1;
|
||||
|
||||
CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
|
||||
CREATE TABLE t2 (a INT, b INT);
|
||||
CREATE TABLE t3 (a INT, c INT);
|
||||
INSERT INTO t1 SELECT 1, a FROM t2 NATURAL JOIN t3
|
||||
ON DUPLICATE KEY UPDATE j= a;
|
||||
DROP TABLE t1,t2,t3;
|
||||
|
||||
CREATE TABLE t1 (i INT PRIMARY KEY, j INT);
|
||||
CREATE TABLE t2 (a INT);
|
||||
INSERT INTO t1 VALUES (1, 1);
|
||||
INSERT INTO t2 VALUES (1), (3);
|
||||
--error ER_BAD_FIELD_ERROR
|
||||
INSERT INTO t1 SELECT 1, COUNT(*) FROM t2 ON DUPLICATE KEY UPDATE j= a;
|
||||
DROP TABLE t1,t2;
|
||||
|
Reference in New Issue
Block a user