2000-12-28 03:56:38 +02:00
|
|
|
#
|
|
|
|
# Problem with INSERT ... SELECT
|
|
|
|
#
|
|
|
|
|
2003-01-06 01:48:59 +02:00
|
|
|
--disable_warnings
|
2005-06-27 16:46:41 +03:00
|
|
|
drop table if exists t1,t2,t3;
|
2003-01-06 01:48:59 +02:00
|
|
|
--enable_warnings
|
|
|
|
|
2000-12-28 03:56:38 +02:00
|
|
|
create table t1 (bandID MEDIUMINT UNSIGNED NOT NULL PRIMARY KEY, payoutID SMALLINT UNSIGNED NOT NULL);
|
|
|
|
insert into t1 (bandID,payoutID) VALUES (1,6),(2,6),(3,4),(4,9),(5,10),(6,1),(7,12),(8,12);
|
|
|
|
create table t2 (payoutID SMALLINT UNSIGNED NOT NULL PRIMARY KEY);
|
|
|
|
insert into t2 (payoutID) SELECT DISTINCT payoutID FROM t1;
|
2007-06-06 10:57:07 -07:00
|
|
|
--error ER_DUP_ENTRY
|
2000-12-28 03:56:38 +02:00
|
|
|
insert into t2 (payoutID) SELECT payoutID+10 FROM t1;
|
2001-11-08 14:17:56 +02:00
|
|
|
insert ignore into t2 (payoutID) SELECT payoutID+10 FROM t1;
|
2000-12-28 03:56:38 +02:00
|
|
|
select * from t2;
|
|
|
|
drop table t1,t2;
|
2003-01-06 01:48:59 +02:00
|
|
|
|
2001-07-26 15:57:34 +02:00
|
|
|
#
|
|
|
|
# bug in bulk insert optimization
|
|
|
|
# test case by Fournier Jocelyn <joc@presence-pc.com>
|
|
|
|
#
|
|
|
|
|
2003-01-06 01:48:59 +02:00
|
|
|
CREATE TABLE `t1` (
|
2001-07-26 15:57:34 +02:00
|
|
|
`numeropost` bigint(20) unsigned NOT NULL default '0',
|
|
|
|
`icone` tinyint(4) unsigned NOT NULL default '0',
|
|
|
|
`numreponse` bigint(20) unsigned NOT NULL auto_increment,
|
|
|
|
`contenu` text NOT NULL,
|
|
|
|
`pseudo` varchar(50) NOT NULL default '',
|
|
|
|
`date` datetime NOT NULL default '0000-00-00 00:00:00',
|
|
|
|
`ip` bigint(11) NOT NULL default '0',
|
|
|
|
`signature` tinyint(1) unsigned NOT NULL default '0',
|
|
|
|
PRIMARY KEY (`numeropost`,`numreponse`)
|
|
|
|
,KEY `ip` (`ip`),
|
|
|
|
KEY `date` (`date`),
|
|
|
|
KEY `pseudo` (`pseudo`),
|
|
|
|
KEY `numreponse` (`numreponse`)
|
2003-12-10 04:31:42 +00:00
|
|
|
) ENGINE=MyISAM;
|
2001-07-26 15:57:34 +02:00
|
|
|
|
2003-01-06 01:48:59 +02:00
|
|
|
CREATE TABLE `t2` (
|
2001-07-26 15:57:34 +02:00
|
|
|
`numeropost` bigint(20) unsigned NOT NULL default '0',
|
|
|
|
`icone` tinyint(4) unsigned NOT NULL default '0',
|
|
|
|
`numreponse` bigint(20) unsigned NOT NULL auto_increment,
|
|
|
|
`contenu` text NOT NULL,
|
|
|
|
`pseudo` varchar(50) NOT NULL default '',
|
|
|
|
`date` datetime NOT NULL default '0000-00-00 00:00:00',
|
|
|
|
`ip` bigint(11) NOT NULL default '0',
|
|
|
|
`signature` tinyint(1) unsigned NOT NULL default '0',
|
|
|
|
PRIMARY KEY (`numeropost`,`numreponse`),
|
|
|
|
KEY `ip` (`ip`),
|
|
|
|
KEY `date` (`date`),
|
|
|
|
KEY `pseudo` (`pseudo`),
|
|
|
|
KEY `numreponse` (`numreponse`)
|
2003-12-10 04:31:42 +00:00
|
|
|
) ENGINE=MyISAM;
|
2001-07-26 15:57:34 +02:00
|
|
|
|
2003-01-06 01:48:59 +02:00
|
|
|
INSERT INTO t2
|
2001-07-26 15:57:34 +02:00
|
|
|
(numeropost,icone,numreponse,contenu,pseudo,date,ip,signature) VALUES
|
|
|
|
(9,1,56,'test','joce','2001-07-25 13:50:53'
|
|
|
|
,3649052399,0);
|
|
|
|
|
|
|
|
|
2003-01-06 01:48:59 +02:00
|
|
|
INSERT INTO t1 (numeropost,icone,contenu,pseudo,date,signature,ip)
|
|
|
|
SELECT 1618,icone,contenu,pseudo,date,signature,ip FROM t2
|
2001-07-26 15:57:34 +02:00
|
|
|
WHERE numeropost=9 ORDER BY numreponse ASC;
|
|
|
|
|
|
|
|
show variables like '%bulk%';
|
|
|
|
|
2003-01-06 01:48:59 +02:00
|
|
|
INSERT INTO t1 (numeropost,icone,contenu,pseudo,date,signature,ip)
|
|
|
|
SELECT 1718,icone,contenu,pseudo,date,signature,ip FROM t2
|
2001-07-26 15:57:34 +02:00
|
|
|
WHERE numeropost=9 ORDER BY numreponse ASC;
|
|
|
|
|
2003-07-01 13:29:55 +03:00
|
|
|
DROP TABLE t1,t2;
|
2001-07-26 15:57:34 +02:00
|
|
|
|
2003-07-03 11:55:36 +03:00
|
|
|
#
|
|
|
|
# Test of insert ... select from same table
|
|
|
|
#
|
|
|
|
|
2003-07-02 00:10:47 +03:00
|
|
|
create table t1 (a int not null);
|
|
|
|
create table t2 (a int not null);
|
|
|
|
insert into t1 values (1);
|
|
|
|
insert into t1 values (a+2);
|
|
|
|
insert into t1 values (a+3);
|
|
|
|
insert into t1 values (4),(a+5);
|
|
|
|
insert into t1 select * from t1;
|
|
|
|
select * from t1;
|
|
|
|
insert into t1 select * from t1 as t2;
|
|
|
|
select * from t1;
|
|
|
|
insert into t2 select * from t1 as t2;
|
|
|
|
select * from t1;
|
|
|
|
insert into t1 select t2.a from t1,t2;
|
|
|
|
select * from t1;
|
2003-07-03 11:55:36 +03:00
|
|
|
--error 1066
|
|
|
|
insert into t1 select * from t1,t1;
|
|
|
|
drop table t1,t2;
|
|
|
|
|
|
|
|
#
|
|
|
|
# test replace ... select
|
|
|
|
#
|
|
|
|
|
|
|
|
create table t1 (a int not null primary key, b char(10));
|
|
|
|
create table t2 (a int not null, b char(10));
|
|
|
|
insert into t1 values (1,"t1:1"),(3,"t1:3");
|
|
|
|
insert into t2 values (2,"t2:2"), (3,"t2:3");
|
2007-06-06 10:57:07 -07:00
|
|
|
--error ER_DUP_ENTRY
|
2003-07-03 11:55:36 +03:00
|
|
|
insert into t1 select * from t2;
|
|
|
|
select * from t1;
|
2004-10-26 19:30:01 +03:00
|
|
|
# REPLACE .. SELECT is not yet supported by PS
|
2003-07-03 11:55:36 +03:00
|
|
|
replace into t1 select * from t2;
|
2012-02-29 21:55:04 +01:00
|
|
|
--sorted_result
|
2003-07-03 11:55:36 +03:00
|
|
|
select * from t1;
|
2003-07-02 00:10:47 +03:00
|
|
|
drop table t1,t2;
|
2003-07-18 04:04:24 +03:00
|
|
|
|
|
|
|
#
|
|
|
|
# Test that caused uninitialized memory access in auto_increment_key update
|
|
|
|
#
|
|
|
|
|
|
|
|
CREATE TABLE t1 ( USID INTEGER UNSIGNED, ServerID TINYINT UNSIGNED, State ENUM ('unknown', 'Access-Granted', 'Session-Active', 'Session-Closed' ) NOT NULL DEFAULT 'unknown', SessionID CHAR(32), User CHAR(32) NOT NULL DEFAULT '<UNKNOWN>', NASAddr INTEGER UNSIGNED, NASPort INTEGER UNSIGNED, NASPortType INTEGER UNSIGNED, ConnectSpeed INTEGER UNSIGNED, CarrierType CHAR(32), CallingStationID CHAR(32), CalledStationID CHAR(32), AssignedAddr INTEGER UNSIGNED, SessionTime INTEGER UNSIGNED, PacketsIn INTEGER UNSIGNED, OctetsIn INTEGER UNSIGNED, PacketsOut INTEGER UNSIGNED, OctetsOut INTEGER UNSIGNED, TerminateCause INTEGER UNSIGNED, UnauthTime TINYINT UNSIGNED, AccessRequestTime DATETIME, AcctStartTime DATETIME, AcctLastTime DATETIME, LastModification TIMESTAMP NOT NULL);
|
|
|
|
CREATE TABLE t2 ( USID INTEGER UNSIGNED AUTO_INCREMENT, ServerID TINYINT UNSIGNED, State ENUM ('unknown', 'Access-Granted', 'Session-Active', 'Session-Closed' ) NOT NULL DEFAULT 'unknown', SessionID CHAR(32), User TEXT NOT NULL, NASAddr INTEGER UNSIGNED, NASPort INTEGER UNSIGNED, NASPortType INTEGER UNSIGNED, ConnectSpeed INTEGER UNSIGNED, CarrierType CHAR(32), CallingStationID CHAR(32), CalledStationID CHAR(32), AssignedAddr INTEGER UNSIGNED, SessionTime INTEGER UNSIGNED, PacketsIn INTEGER UNSIGNED, OctetsIn INTEGER UNSIGNED, PacketsOut INTEGER UNSIGNED, OctetsOut INTEGER UNSIGNED, TerminateCause INTEGER UNSIGNED, UnauthTime TINYINT UNSIGNED, AccessRequestTime DATETIME, AcctStartTime DATETIME, AcctLastTime DATETIME, LastModification TIMESTAMP NOT NULL, INDEX(USID,ServerID,NASAddr,SessionID), INDEX(AssignedAddr));
|
|
|
|
INSERT INTO t1 VALUES (39,42,'Access-Granted','46','491721000045',2130706433,17690,NULL,NULL,'Localnet','491721000045','49172200000',754974766,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'2003-07-18 00:11:21',NULL,NULL,20030718001121);
|
|
|
|
INSERT INTO t2 SELECT USID, ServerID, State, SessionID, User, NASAddr, NASPort, NASPortType, ConnectSpeed, CarrierType, CallingStationID, CalledStationID, AssignedAddr, SessionTime, PacketsIn, OctetsIn, PacketsOut, OctetsOut, TerminateCause, UnauthTime, AccessRequestTime, AcctStartTime, AcctLastTime, LastModification from t1 LIMIT 1;
|
|
|
|
drop table t1,t2;
|
2004-02-06 16:40:44 +03:00
|
|
|
|
|
|
|
#
|
2003-12-16 17:55:34 -04:00
|
|
|
# Another problem from Bug #2012
|
|
|
|
#
|
|
|
|
|
|
|
|
CREATE TABLE t1(
|
|
|
|
Month date NOT NULL,
|
|
|
|
Type tinyint(3) unsigned NOT NULL auto_increment,
|
|
|
|
Field int(10) unsigned NOT NULL,
|
|
|
|
Count int(10) unsigned NOT NULL,
|
|
|
|
UNIQUE KEY Month (Month,Type,Field)
|
|
|
|
);
|
|
|
|
|
|
|
|
insert into t1 Values
|
|
|
|
(20030901, 1, 1, 100),
|
|
|
|
(20030901, 1, 2, 100),
|
|
|
|
(20030901, 2, 1, 100),
|
|
|
|
(20030901, 2, 2, 100),
|
|
|
|
(20030901, 3, 1, 100);
|
|
|
|
|
|
|
|
select * from t1;
|
|
|
|
|
|
|
|
Select null, Field, Count From t1 Where Month=20030901 and Type=2;
|
|
|
|
|
|
|
|
create table t2(No int not null, Field int not null, Count int not null);
|
|
|
|
|
2017-02-08 15:28:00 -05:00
|
|
|
insert ignore into t2 Select null, Field, Count From t1 Where Month=20030901 and Type=2;
|
2003-12-16 17:55:34 -04:00
|
|
|
|
|
|
|
select * from t2;
|
|
|
|
|
|
|
|
drop table t1, t2;
|
2005-01-19 21:20:55 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# BUG#6034 - Error code 124: Wrong medium type
|
|
|
|
#
|
|
|
|
CREATE TABLE t1 (
|
|
|
|
ID int(11) NOT NULL auto_increment,
|
|
|
|
NO int(11) NOT NULL default '0',
|
|
|
|
SEQ int(11) NOT NULL default '0',
|
|
|
|
PRIMARY KEY (ID),
|
|
|
|
KEY t1$NO (SEQ,NO)
|
|
|
|
) ENGINE=MyISAM;
|
|
|
|
INSERT INTO t1 (SEQ, NO) SELECT "1" AS SEQ, IF(MAX(NO) IS NULL, 0, MAX(NO)) + 1 AS NO FROM t1 WHERE (SEQ = 1);
|
|
|
|
select SQL_BUFFER_RESULT * from t1 WHERE (SEQ = 1);
|
|
|
|
drop table t1;
|
|
|
|
|
2005-06-21 22:24:58 +04:00
|
|
|
#
|
|
|
|
# Bug#10886 - Have to restore default values after update ON DUPLICATE KEY
|
|
|
|
#
|
|
|
|
create table t1 (f1 int);
|
|
|
|
create table t2 (ff1 int unique, ff2 int default 1);
|
|
|
|
insert into t1 values (1),(1),(2);
|
|
|
|
insert into t2(ff1) select f1 from t1 on duplicate key update ff2=ff2+1;
|
|
|
|
select * from t2;
|
|
|
|
drop table t1, t2;
|
2005-06-22 07:18:42 +04:00
|
|
|
#
|
|
|
|
# BUGS #9728 - 'Decreased functionality in "on duplicate key update"'
|
|
|
|
# #8147 - 'a column proclaimed ambigous in INSERT ... SELECT .. ON
|
|
|
|
# DUPLICATE'
|
|
|
|
#
|
|
|
|
create table t1 (a int unique);
|
|
|
|
create table t2 (a int, b int);
|
2005-06-27 16:46:41 +03:00
|
|
|
create table t3 (c int, d int);
|
2005-06-22 07:18:42 +04:00
|
|
|
insert into t1 values (1),(2);
|
|
|
|
insert into t2 values (1,2);
|
2005-06-27 16:46:41 +03:00
|
|
|
insert into t3 values (1,6),(3,7);
|
2005-06-22 07:18:42 +04:00
|
|
|
select * from t1;
|
2005-06-27 16:46:41 +03:00
|
|
|
insert into t1 select a from t2 on duplicate key update a= t1.a + t2.b;
|
2005-06-22 07:18:42 +04:00
|
|
|
select * from t1;
|
2005-06-27 16:46:41 +03:00
|
|
|
insert into t1 select a+1 from t2 on duplicate key update t1.a= t1.a + t2.b+1;
|
|
|
|
select * from t1;
|
|
|
|
insert into t1 select t3.c from t3 on duplicate key update a= a + t3.d;
|
|
|
|
select * from t1;
|
|
|
|
insert into t1 select t2.a from t2 group by t2.a on duplicate key update a= a + 10;
|
|
|
|
|
|
|
|
#Some error cases
|
|
|
|
--error 1052
|
|
|
|
insert into t1 select t2.a from t2 on duplicate key update a= a + t2.b;
|
Implementation of WL#2486 -
"Process NATURAL and USING joins according to SQL:2003".
* Some of the main problems fixed by the patch:
- in "select *" queries the * expanded correctly according to
ANSI for arbitrary natural/using joins
- natural/using joins are correctly transformed into JOIN ... ON
for any number/nesting of the joins.
- column references are correctly resolved against natural joins
of any nesting and combined with arbitrary other joins.
* This patch also contains a fix for name resolution of items
inside the ON condition of JOIN ... ON - in this case items must
be resolved only against the JOIN operands. To support such
'local' name resolution, the patch introduces a stack of
name resolution contexts used at parse time.
NOTICE:
- This patch is not complete in the sense that
- there are 2 test cases that still do not pass -
one in join.test, one in select.test. Both are marked
with a comment "TODO: WL#2486".
- it does not include a new test specific for the task
mysql-test/include/ps_query.inc:
Adjusted according to standard NATURAL/USING join semantics.,
mysql-test/r/bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/derived.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/errors.result:
The column as a whole cannot be resolved, so different error message.
mysql-test/r/fulltext.result:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/r/fulltext_order_by.result:
More detailed error message.
mysql-test/r/innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/r/insert_select.result:
More detailed error message.
mysql-test/r/join.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/r/join_crash.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_nested.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_outer.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/multi_update.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/null_key.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/order_by.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_2myisam.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_3innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_4heap.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_5merge.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_6bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_7ndb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/select.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one failing test case which is commented with
WL#2486 in the test file.
mysql-test/r/subselect.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/type_ranges.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/union.result:
More detailed error message.
mysql-test/t/bdb.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/errors.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/fulltext.test:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/t/fulltext_order_by.test:
More detailed error message.
mysql-test/t/innodb.test:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/t/insert_select.test:
More detailed error message.
mysql-test/t/join.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/join_crash.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_nested.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_outer.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/null_key.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/order_by.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/select.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/subselect.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/type_ranges.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/union.test:
More detailed error message.
sql/item.cc:
- extra parameter to find_field_in_tables
- find_field_in_real_table renamed to find_field_in_table
- fixed comments/typos
sql/item.h:
- added [first | last]_name_resolution_table to class
Name_resolution_context
- commented old code
- standardized formatting
sql/mysql_priv.h:
- refactored the find_field_in_XXX procedures,
- added a new procedure for natural join table references,
- renamed the find_field_in_XXX procedures to clearer names
sql/sp.cc:
- pass the top-most list of the FROM clause to setup_tables
- extra parameter to find_field_in_tables
sql/sql_acl.cc:
- renamed find_field_in_table => find_field_in_table_ref
- extra parameter to find_field_in_table_ref
- commented old code
sql/sql_base.cc:
This file contains the core of the implementation of the processing
of NATURAL/USING joins (WL#2486).
- added many comments to old code
- refactored the group of find_field_in_XXX procedures, and added a
new procedure for natural joins. There is one find_field_in_XXX procedure
per each type of table reference (stored table, merge view, or natural
join); one meta-procedure that selects the correct one depeneding on the
table reference; and one procedure that goes over a list of table
referenes.
- NATURAL/USING joins are processed through the procedures:
mark_common_columns, store_natural_using_join_columns,
store_top_level_join_columns, setup_natural_join_row_types.
The entry point to processing NATURAL/USING joins is the
procedure 'setup_natural_join_row_types'.
- Replaced the specialized Field_iterator_XXX iterators with one
generic iterator over the fields of a table reference.
- Simplified 'insert_fields' and 'setup_conds' due to encapsulation of
the processing of natural joins in a separate set of procedures.
sql/sql_class.h:
- Commented old code.
sql/sql_delete.cc:
- Pass the FROM clause to setup_tables.
sql/sql_help.cc:
- pass the end name resolution table to find_field_in_tables
- adjust the list of tables for name resolution
sql/sql_insert.cc:
- Changed the code that saves and restores the current context to
support the list of tables for name resolution -
context->first_name_resolution_table, and
table_list->next_name_resolution_table.
Needed to support an ugly trick to resolve inserted columns only in
the first table.
- Added Name_resolution_context::[first | last]_name_resolution_table.
- Commented old code
sql/sql_lex.cc:
- set select_lex.parent_lex correctly
- set correct state of the current name resolution context
sql/sql_lex.h:
- Added a stack of name resolution contexts to support local
contexts for JOIN ... ON conditions.
- Commented old code.
sql/sql_load.cc:
- Pass the FROM clause to setup_tables.
sql/sql_olap.cc:
- Pass the FROM clause to setup_tables.
sql/sql_parse.cc:
- correctly set SELECT_LEX::parent_lex
- set the first table of the current name resoltion context
- added support for NATURAL/USING joins
- commented old code
sql/sql_select.cc:
- Pass the FROM clause to setup_tables.
- Pass the end table to find_field_in_tables
- Improved comments
sql/sql_show.cc:
- Set SELECT_LEX::parent_lex.
sql/sql_update.cc:
- Pass the FROM clause to setup_tables.
sql/sql_yacc.yy:
- Added support for a stack of name resolution contexts needed to
implement name resolution for JOIN ... ON. A context is pushed
for each new JOIN ... ON, and popped afterwards.
- Added support for NATURAL/USING joins.
sql/table.cc:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
sql/table.h:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
tests/mysql_client_test.c:
Adjusted according to standard NATURAL JOIN syntax.
2005-08-12 17:57:19 +03:00
|
|
|
--error 1054
|
2005-06-27 16:46:41 +03:00
|
|
|
insert into t1 select t2.a from t2 on duplicate key update t2.a= a + t2.b;
|
Implementation of WL#2486 -
"Process NATURAL and USING joins according to SQL:2003".
* Some of the main problems fixed by the patch:
- in "select *" queries the * expanded correctly according to
ANSI for arbitrary natural/using joins
- natural/using joins are correctly transformed into JOIN ... ON
for any number/nesting of the joins.
- column references are correctly resolved against natural joins
of any nesting and combined with arbitrary other joins.
* This patch also contains a fix for name resolution of items
inside the ON condition of JOIN ... ON - in this case items must
be resolved only against the JOIN operands. To support such
'local' name resolution, the patch introduces a stack of
name resolution contexts used at parse time.
NOTICE:
- This patch is not complete in the sense that
- there are 2 test cases that still do not pass -
one in join.test, one in select.test. Both are marked
with a comment "TODO: WL#2486".
- it does not include a new test specific for the task
mysql-test/include/ps_query.inc:
Adjusted according to standard NATURAL/USING join semantics.,
mysql-test/r/bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/derived.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/errors.result:
The column as a whole cannot be resolved, so different error message.
mysql-test/r/fulltext.result:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/r/fulltext_order_by.result:
More detailed error message.
mysql-test/r/innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/r/insert_select.result:
More detailed error message.
mysql-test/r/join.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/r/join_crash.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_nested.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/join_outer.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/multi_update.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/null_key.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/order_by.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_2myisam.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_3innodb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_4heap.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_5merge.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_6bdb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/ps_7ndb.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/select.result:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one failing test case which is commented with
WL#2486 in the test file.
mysql-test/r/subselect.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/type_ranges.result:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/r/union.result:
More detailed error message.
mysql-test/t/bdb.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/errors.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/fulltext.test:
Adjusted according to standard JOIN ... ON semantics =>
the ON condition can refer only to the join operands.
mysql-test/t/fulltext_order_by.test:
More detailed error message.
mysql-test/t/innodb.test:
Adjusted according to standard NATURAL/USING join semantics.
This test doesn't pass completetly yet!
mysql-test/t/insert_select.test:
More detailed error message.
mysql-test/t/join.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/join_crash.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_nested.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/join_outer.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/null_key.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/order_by.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/select.test:
Adjusted according to standard NATURAL/USING join semantics.
NOTICE: there is one test case that still fails, and it is
commeted out and marked with WL#2486 in the test file.
mysql-test/t/subselect.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/type_ranges.test:
Adjusted according to standard NATURAL/USING join semantics.
mysql-test/t/union.test:
More detailed error message.
sql/item.cc:
- extra parameter to find_field_in_tables
- find_field_in_real_table renamed to find_field_in_table
- fixed comments/typos
sql/item.h:
- added [first | last]_name_resolution_table to class
Name_resolution_context
- commented old code
- standardized formatting
sql/mysql_priv.h:
- refactored the find_field_in_XXX procedures,
- added a new procedure for natural join table references,
- renamed the find_field_in_XXX procedures to clearer names
sql/sp.cc:
- pass the top-most list of the FROM clause to setup_tables
- extra parameter to find_field_in_tables
sql/sql_acl.cc:
- renamed find_field_in_table => find_field_in_table_ref
- extra parameter to find_field_in_table_ref
- commented old code
sql/sql_base.cc:
This file contains the core of the implementation of the processing
of NATURAL/USING joins (WL#2486).
- added many comments to old code
- refactored the group of find_field_in_XXX procedures, and added a
new procedure for natural joins. There is one find_field_in_XXX procedure
per each type of table reference (stored table, merge view, or natural
join); one meta-procedure that selects the correct one depeneding on the
table reference; and one procedure that goes over a list of table
referenes.
- NATURAL/USING joins are processed through the procedures:
mark_common_columns, store_natural_using_join_columns,
store_top_level_join_columns, setup_natural_join_row_types.
The entry point to processing NATURAL/USING joins is the
procedure 'setup_natural_join_row_types'.
- Replaced the specialized Field_iterator_XXX iterators with one
generic iterator over the fields of a table reference.
- Simplified 'insert_fields' and 'setup_conds' due to encapsulation of
the processing of natural joins in a separate set of procedures.
sql/sql_class.h:
- Commented old code.
sql/sql_delete.cc:
- Pass the FROM clause to setup_tables.
sql/sql_help.cc:
- pass the end name resolution table to find_field_in_tables
- adjust the list of tables for name resolution
sql/sql_insert.cc:
- Changed the code that saves and restores the current context to
support the list of tables for name resolution -
context->first_name_resolution_table, and
table_list->next_name_resolution_table.
Needed to support an ugly trick to resolve inserted columns only in
the first table.
- Added Name_resolution_context::[first | last]_name_resolution_table.
- Commented old code
sql/sql_lex.cc:
- set select_lex.parent_lex correctly
- set correct state of the current name resolution context
sql/sql_lex.h:
- Added a stack of name resolution contexts to support local
contexts for JOIN ... ON conditions.
- Commented old code.
sql/sql_load.cc:
- Pass the FROM clause to setup_tables.
sql/sql_olap.cc:
- Pass the FROM clause to setup_tables.
sql/sql_parse.cc:
- correctly set SELECT_LEX::parent_lex
- set the first table of the current name resoltion context
- added support for NATURAL/USING joins
- commented old code
sql/sql_select.cc:
- Pass the FROM clause to setup_tables.
- Pass the end table to find_field_in_tables
- Improved comments
sql/sql_show.cc:
- Set SELECT_LEX::parent_lex.
sql/sql_update.cc:
- Pass the FROM clause to setup_tables.
sql/sql_yacc.yy:
- Added support for a stack of name resolution contexts needed to
implement name resolution for JOIN ... ON. A context is pushed
for each new JOIN ... ON, and popped afterwards.
- Added support for NATURAL/USING joins.
sql/table.cc:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
sql/table.h:
- Added new class Natural_join_column to hide the heterogeneous
representation of column references for stored tables and for
views.
- Added a new list TABLE_LIST::next_name_resolution_table to
support name resolution with NATURAL/USING joins. Also added
other members to TABLE_LIST to support NATURAL/USING joins.
- Added a generic iterator over the fields of table references
of various types - class Field_iterator_table_ref
tests/mysql_client_test.c:
Adjusted according to standard NATURAL JOIN syntax.
2005-08-12 17:57:19 +03:00
|
|
|
--error 1054
|
2005-06-27 16:46:41 +03:00
|
|
|
insert into t1 select t2.a from t2 group by t2.a on duplicate key update a= t1.a + t2.b;
|
|
|
|
drop table t1,t2,t3;
|
2005-07-28 03:22:47 +03:00
|
|
|
|
2005-09-10 02:30:26 +04:00
|
|
|
#
|
|
|
|
# Bug #12695 Item_func_isnull::update_used_tables() did not update
|
|
|
|
# const_item_cache
|
|
|
|
create table t1(f1 varchar(5) key);
|
|
|
|
insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1;
|
|
|
|
insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1;
|
|
|
|
insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1;
|
|
|
|
select * from t1;
|
|
|
|
drop table t1;
|
|
|
|
|
2005-10-25 20:04:12 +04:00
|
|
|
#
|
|
|
|
# Bug #13392 values() fails with 'ambiguous' or returns NULL
|
|
|
|
# with ON DUPLICATE and SELECT
|
|
|
|
create table t1(x int, y int);
|
|
|
|
create table t2(x int, z int);
|
|
|
|
insert into t1(x,y) select x,z from t2 on duplicate key update x=values(x);
|
|
|
|
--error 1054
|
|
|
|
insert into t1(x,y) select x,z from t2 on duplicate key update x=values(z);
|
2005-10-28 02:36:19 +03:00
|
|
|
--error 1054
|
2005-10-25 20:04:12 +04:00
|
|
|
insert into t1(x,y) select x,z from t2 on duplicate key update x=values(t2.x);
|
|
|
|
drop table t1,t2;
|
|
|
|
|
2006-06-19 13:22:42 +03:00
|
|
|
#
|
|
|
|
# Bug #9676: INSERT INTO x SELECT .. FROM x LIMIT 1; slows down with big
|
|
|
|
# tables
|
|
|
|
#
|
|
|
|
|
|
|
|
#Note: not an exsaustive test : just a check of the code path.
|
|
|
|
CREATE TABLE t1 (a int PRIMARY KEY);
|
|
|
|
INSERT INTO t1 values (1), (2);
|
|
|
|
|
2007-06-24 01:20:14 +05:00
|
|
|
flush status;
|
2006-06-19 13:22:42 +03:00
|
|
|
INSERT INTO t1 SELECT a + 2 FROM t1 LIMIT 1;
|
2007-06-24 01:20:14 +05:00
|
|
|
show status like 'Handler_read%';
|
2006-06-19 13:22:42 +03:00
|
|
|
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
2007-07-31 10:46:04 +05:00
|
|
|
#
|
|
|
|
# Bug #29717 INSERT INTO SELECT inserts values even if SELECT statement itself returns empty
|
|
|
|
#
|
|
|
|
|
|
|
|
CREATE TABLE t1 (
|
|
|
|
f1 int(10) unsigned NOT NULL auto_increment PRIMARY KEY,
|
|
|
|
f2 varchar(100) NOT NULL default ''
|
|
|
|
);
|
|
|
|
CREATE TABLE t2 (
|
|
|
|
f1 varchar(10) NOT NULL default '',
|
|
|
|
f2 char(3) NOT NULL default '',
|
|
|
|
PRIMARY KEY (`f1`),
|
|
|
|
KEY `k1` (`f2`, `f1`)
|
|
|
|
);
|
|
|
|
|
|
|
|
INSERT INTO t1 values(NULL, '');
|
|
|
|
INSERT INTO `t2` VALUES ('486878','WDT'),('486910','WDT');
|
|
|
|
SELECT COUNT(*) FROM t1;
|
|
|
|
|
|
|
|
SELECT min(t2.f1) FROM t1, t2 where t2.f2 = 'SIR' GROUP BY t1.f1;
|
|
|
|
|
|
|
|
INSERT INTO t1 (f2)
|
|
|
|
SELECT min(t2.f1) FROM t1, t2 where t2.f2 = 'SIR' GROUP BY t1.f1;
|
|
|
|
|
|
|
|
SELECT COUNT(*) FROM t1;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
DROP TABLE t1, t2;
|
|
|
|
|
2005-07-28 03:22:47 +03:00
|
|
|
# End of 4.1 tests
|
2006-06-19 17:34:12 +03:00
|
|
|
|
|
|
|
#
|
|
|
|
# Bug #18080: INSERT ... SELECT ... JOIN results in ambiguous field list error
|
|
|
|
#
|
|
|
|
CREATE TABLE t1 (x int, y int);
|
|
|
|
CREATE TABLE t2 (z int, y int);
|
|
|
|
CREATE TABLE t3 (a int, b int);
|
|
|
|
INSERT INTO t3 (SELECT x, y FROM t1 JOIN t2 USING (y) WHERE z = 1);
|
|
|
|
DROP TABLE IF EXISTS t1,t2,t3;
|
2006-07-19 11:49:07 +02:00
|
|
|
|
2006-09-12 17:50:24 +03:00
|
|
|
#
|
|
|
|
# Bug #21774: Column count doesn't match value count at row x
|
|
|
|
#
|
|
|
|
CREATE DATABASE bug21774_1;
|
|
|
|
CREATE DATABASE bug21774_2;
|
|
|
|
|
|
|
|
CREATE TABLE bug21774_1.t1(id VARCHAR(10) NOT NULL,label VARCHAR(255));
|
|
|
|
CREATE TABLE bug21774_2.t1(id VARCHAR(10) NOT NULL,label VARCHAR(255));
|
|
|
|
CREATE TABLE bug21774_1.t2(id VARCHAR(10) NOT NULL,label VARCHAR(255));
|
|
|
|
|
|
|
|
INSERT INTO bug21774_2.t1 SELECT t1.* FROM bug21774_1.t1;
|
|
|
|
|
|
|
|
use bug21774_1;
|
|
|
|
INSERT INTO bug21774_2.t1 SELECT t1.* FROM t1;
|
|
|
|
|
|
|
|
DROP DATABASE bug21774_1;
|
|
|
|
DROP DATABASE bug21774_2;
|
2007-02-07 00:46:03 +03:00
|
|
|
USE test;
|
2006-09-12 17:50:24 +03:00
|
|
|
|
2007-02-07 00:46:03 +03:00
|
|
|
#
|
|
|
|
# Bug#19978: INSERT .. ON DUPLICATE erroneously reports some records were
|
|
|
|
# updated.
|
|
|
|
#
|
|
|
|
create table t1(f1 int primary key, f2 int);
|
|
|
|
--enable_info
|
|
|
|
insert into t1 values (1,1);
|
|
|
|
insert into t1 values (1,1) on duplicate key update f2=1;
|
|
|
|
insert into t1 values (1,1) on duplicate key update f2=2;
|
|
|
|
--disable_info
|
|
|
|
select * from t1;
|
|
|
|
drop table t1;
|
2007-02-09 22:25:09 +03:00
|
|
|
|
2007-02-16 19:39:28 +03:00
|
|
|
#
|
|
|
|
# Bug#16630: wrong result, when INSERT t1 SELECT ... FROM t1 ON DUPLICATE
|
|
|
|
#
|
|
|
|
CREATE TABLE t1 (f1 INT, f2 INT );
|
|
|
|
CREATE TABLE t2 (f1 INT PRIMARY KEY, f2 INT);
|
|
|
|
INSERT INTO t1 VALUES (1,1),(2,2),(10,10);
|
|
|
|
INSERT INTO t2 (f1, f2) SELECT f1, f2 FROM t1;
|
|
|
|
INSERT INTO t2 (f1, f2)
|
|
|
|
SELECT f1, f1 FROM t2 src WHERE f1 < 2
|
|
|
|
ON DUPLICATE KEY UPDATE f1 = 100 + src.f1;
|
2012-02-29 21:55:04 +01:00
|
|
|
--sorted_result
|
2007-02-16 19:39:28 +03:00
|
|
|
SELECT * FROM t2;
|
|
|
|
DROP TABLE t1, t2;
|
|
|
|
|
2009-05-04 14:45:36 +02:00
|
|
|
#
|
|
|
|
# Bug#44306: Assertion fail on duplicate key error in 'INSERT ... SELECT'
|
|
|
|
# statements
|
|
|
|
#
|
2017-02-08 15:28:00 -05:00
|
|
|
SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
|
2009-05-04 14:45:36 +02:00
|
|
|
CREATE TABLE t1 ( a INT KEY, b INT );
|
|
|
|
INSERT INTO t1 VALUES ( 0, 1 );
|
|
|
|
--error ER_DUP_ENTRY
|
|
|
|
INSERT INTO t1 ( b ) SELECT MAX( b ) FROM t1 WHERE b = 2;
|
|
|
|
DROP TABLE t1;
|
2017-02-08 15:28:00 -05:00
|
|
|
SET sql_mode = DEFAULT;
|
2009-05-04 14:45:36 +02:00
|
|
|
|
2007-03-22 18:44:16 +02:00
|
|
|
#
|
|
|
|
# Bug #26207: inserts don't work with shortened index
|
|
|
|
#
|
|
|
|
SET SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
|
|
|
|
|
|
|
|
CREATE TABLE t1 (c VARCHAR(30), INDEX ix_c (c(10)));
|
|
|
|
CREATE TABLE t2 (d VARCHAR(10));
|
|
|
|
INSERT INTO t1 (c) VALUES ('7_chars'), ('13_characters');
|
|
|
|
|
|
|
|
EXPLAIN
|
|
|
|
SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c='13_characters') FROM t1;
|
|
|
|
|
|
|
|
SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c='13_characters') FROM t1;
|
|
|
|
|
|
|
|
INSERT INTO t2 (d)
|
|
|
|
SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c='13_characters') FROM t1;
|
|
|
|
|
|
|
|
INSERT INTO t2 (d)
|
|
|
|
SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c='7_chars') FROM t1;
|
|
|
|
|
|
|
|
INSERT INTO t2 (d)
|
|
|
|
SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c IN (SELECT t1.c FROM t1))
|
|
|
|
FROM t1;
|
|
|
|
|
|
|
|
SELECT * FROM t2;
|
|
|
|
DROP TABLE t1,t2;
|
2007-06-24 01:20:14 +05:00
|
|
|
|
|
|
|
#
|
|
|
|
# Bug #29095: incorrect pushing of LIMIT into the temporary
|
|
|
|
# table ignoring ORDER BY clause
|
|
|
|
#
|
|
|
|
|
|
|
|
CREATE TABLE t1 (
|
|
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
prev_id INT,
|
|
|
|
join_id INT DEFAULT 0);
|
|
|
|
|
|
|
|
INSERT INTO t1 (prev_id) VALUES (NULL), (1), (2);
|
|
|
|
SELECT * FROM t1;
|
|
|
|
|
|
|
|
CREATE TABLE t2 (join_id INT);
|
|
|
|
INSERT INTO t2 (join_id) VALUES (0);
|
|
|
|
|
|
|
|
INSERT INTO t1 (prev_id) SELECT id
|
|
|
|
FROM t2 LEFT JOIN t1 ON t1.join_id = t2.join_id
|
|
|
|
ORDER BY id DESC LIMIT 1;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
|
|
|
|
DROP TABLE t1,t2;
|
2007-09-21 12:09:00 +04:00
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # Bug#30384: Having SQL_BUFFER_RESULT option in the
|
|
|
|
--echo # CREATE .. KEY(..) .. SELECT led to creating corrupted index.
|
|
|
|
--echo #
|
|
|
|
create table t1(f1 int);
|
|
|
|
insert into t1 values(1),(2),(3);
|
|
|
|
create table t2 (key(f1)) engine=myisam select sql_buffer_result f1 from t1;
|
|
|
|
check table t2 extended;
|
|
|
|
drop table t1,t2;
|
|
|
|
|
2009-07-24 15:50:45 +04:00
|
|
|
--echo End of 5.0 tests
|
2009-11-16 21:49:51 +01:00
|
|
|
|
|
|
|
# The following is not relevant for MariaDB as we are using Maria for
|
|
|
|
# tmp tables.
|
|
|
|
|
|
|
|
--echo ##################################################################
|
2009-07-24 15:50:45 +04:00
|
|
|
--echo #
|
|
|
|
--echo # Bug #46075: Assertion failed: 0, file .\protocol.cc, line 416
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
CREATE TABLE t1(a INT);
|
|
|
|
# To force MyISAM temp. table in the following INSERT ... SELECT.
|
|
|
|
SET max_heap_table_size = 16384;
|
|
|
|
# To overflow the temp. table.
|
|
|
|
SET @old_myisam_data_pointer_size = @@myisam_data_pointer_size;
|
|
|
|
SET GLOBAL myisam_data_pointer_size = 2;
|
|
|
|
|
|
|
|
INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
|
|
|
|
|
2011-02-16 21:43:12 +01:00
|
|
|
call mtr.add_suppression("mysqld.*: The table '.*#sql.*' is full");
|
2011-07-02 22:12:12 +02:00
|
|
|
--error 0,ER_RECORD_FILE_FULL,ER_RECORD_FILE_FULL
|
2009-07-24 15:50:45 +04:00
|
|
|
INSERT IGNORE INTO t1 SELECT t1.a FROM t1,t1 t2,t1 t3,t1 t4,t1 t5,t1 t6,t1 t7;
|
|
|
|
|
|
|
|
# Cleanup
|
|
|
|
SET GLOBAL myisam_data_pointer_size = @old_myisam_data_pointer_size;
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
2009-11-16 21:49:51 +01:00
|
|
|
--echo End of 5.1 tests
|
2018-05-15 17:34:47 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# MDEV-15318 CREATE .. SELECT VALUES produces invalid table structure
|
|
|
|
#
|
|
|
|
create table t1 (i int);
|
2018-05-22 11:47:09 +02:00
|
|
|
create table t2 as select value(i) as a from t1;
|
2018-05-15 17:34:47 +02:00
|
|
|
show create table t2;
|
|
|
|
drop table t1, t2;
|
|
|
|
|
|
|
|
--echo End of 5.5 tests
|
2021-12-24 14:00:47 +05:30
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # Beginning of 10.2 test
|
|
|
|
--echo #
|
|
|
|
--echo # MDEV-26698: Incorrect row number upon INSERT .. SELECT from the same
|
|
|
|
--echo # table: rows are counted twice
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
CREATE TABLE t1(a TINYINT);
|
|
|
|
|
|
|
|
INSERT INTO t1 VALUES (1), (100);
|
|
|
|
|
|
|
|
INSERT INTO t1 SELECT a*2 FROM t1;
|
|
|
|
|
|
|
|
TRUNCATE TABLE t1;
|
|
|
|
|
|
|
|
--echo # using ORDER BY
|
|
|
|
|
|
|
|
INSERT INTO t1 VALUES(1), (2), (100), (3);
|
|
|
|
|
|
|
|
INSERT INTO t1 SELECT a*2 FROM t1 ORDER BY a;
|
|
|
|
|
|
|
|
DROP TABLE t1;
|
|
|
|
|
2022-06-18 20:54:39 +07:00
|
|
|
#
|
|
|
|
# MDEV-26427 MariaDB Server SEGV on INSERT .. SELECT
|
|
|
|
#
|
|
|
|
CREATE TABLE t1 (a INT, b INT);
|
|
|
|
INSERT INTO t1 (a) SELECT SUM(1);
|
|
|
|
INSERT INTO t1 (a, b) SELECT AVG(2), MIN(3);
|
|
|
|
|
|
|
|
--error ER_TRUNCATED_WRONG_VALUE
|
|
|
|
INSERT INTO t1 (b) SELECT AVG('x') OVER ();
|
|
|
|
INSERT INTO t1 SELECT MIN(7) OVER (), MAX(8) OVER();
|
|
|
|
SELECT * FROM t1;
|
|
|
|
|
|
|
|
PREPARE stmt FROM 'INSERT INTO t1 (a) SELECT AVG(?)';
|
|
|
|
EXECUTE stmt USING 9;
|
|
|
|
EXECUTE stmt USING 10;
|
|
|
|
|
|
|
|
PREPARE stmt FROM 'INSERT INTO t1 SELECT MIN(?), MAX(?)';
|
|
|
|
EXECUTE stmt USING 11, 12;
|
|
|
|
EXECUTE stmt USING 13, 14;
|
|
|
|
DEALLOCATE PREPARE stmt;
|
|
|
|
SELECT * FROM t1;
|
|
|
|
|
|
|
|
DELIMITER //;
|
|
|
|
CREATE PROCEDURE p1(param_a INT, param_b INT)
|
|
|
|
BEGIN
|
|
|
|
INSERT INTO t1 SELECT MIN(param_a) OVER (), MAX(param_b);
|
|
|
|
END//
|
|
|
|
DELIMITER ;//
|
|
|
|
CALL p1(21, 22);
|
|
|
|
CALL p1(23, 24);
|
|
|
|
SELECT * FROM t1;
|
|
|
|
|
|
|
|
CREATE TABLE t2 (
|
|
|
|
a DECIMAL UNIQUE CHECK (CASE 0 * 27302337.000000 WHEN 34 THEN
|
|
|
|
+ 'x' LIKE 'x' OR a NOT IN (-1 / TRUE ^ 2) ELSE 7105743.000000 END));
|
|
|
|
INSERT INTO t2 VALUES (90),( -1),(31152443.000000),(-32768),(NULL),(NULL);
|
|
|
|
--error ER_TRUNCATED_WRONG_VALUE
|
|
|
|
INSERT INTO t2 SELECT AVG('x') OVER (
|
|
|
|
PARTITION BY ((NOT AVG(76698761.000000))) IS NOT NULL);
|
|
|
|
INSERT IGNORE INTO t2 () VALUES (0),('x'),(3751286.000000),
|
|
|
|
('x'),((a = 'x' AND 0 AND 0));
|
|
|
|
INSERT INTO t2 VALUES (127);
|
|
|
|
--error ER_DUP_ENTRY
|
|
|
|
INSERT INTO t2 SELECT -2147483648 END FROM t2 AS TEXT JOIN t2 JOIN t2 TABLES;
|
|
|
|
--error ER_TRUNCATED_WRONG_VALUE
|
|
|
|
ALTER TABLE t2 ADD (
|
|
|
|
b INT UNIQUE CHECK ((a = 'x' AND ((-(+(BINARY 49730460.000000)))) = 'x'
|
|
|
|
BETWEEN 'x' AND 'x')));
|
|
|
|
--error ER_DUP_ENTRY
|
|
|
|
UPDATE t2 SET a = -128 WHERE a IS NULL ORDER BY 78 IN ('x','x'),a;
|
|
|
|
|
|
|
|
DROP TABLE t1, t2;
|
|
|
|
DROP PROCEDURE p1;
|
|
|
|
|
2021-12-24 14:00:47 +05:30
|
|
|
--echo # End of 10.2 test
|
2022-08-01 20:52:10 -07:00
|
|
|
|
|
|
|
--echo #
|
|
|
|
--echo # MDEV-28617: INSERT ... SELECT with redundant IN subquery in GROUP BY
|
|
|
|
--echo # list that uses mergeable derived table containing
|
|
|
|
--echo # reference to target table
|
|
|
|
--echo #
|
|
|
|
|
|
|
|
create table t1 (a int);
|
|
|
|
create table t2 (b int);
|
|
|
|
create table t3 (c int);
|
|
|
|
|
|
|
|
insert into t1 values (3), (1);
|
|
|
|
insert into t2 values (3), (2);
|
|
|
|
insert into t3 values (4), (2);
|
|
|
|
|
|
|
|
insert into t1
|
|
|
|
select b from t2
|
|
|
|
where b in (select c from t3
|
|
|
|
group by (select * from (select a from t1) dt where a = 1));
|
|
|
|
select * from t1;
|
|
|
|
|
|
|
|
delete from t1;
|
|
|
|
insert into t1 values (3), (1);
|
|
|
|
|
|
|
|
insert into t1
|
|
|
|
select b from t2
|
|
|
|
where b >= any (select c from t3
|
|
|
|
group by (select * from (select a from t1) dt where a = 1));
|
|
|
|
select * from t1;
|
|
|
|
|
|
|
|
delete from t1;
|
|
|
|
insert into t1 values (3), (1);
|
|
|
|
|
|
|
|
insert into t1
|
|
|
|
select b from t2
|
|
|
|
where b <= all (select c from t3
|
|
|
|
group by (select * from (select a from t1) dt where a = 1));
|
|
|
|
select * from t1;
|
|
|
|
|
|
|
|
delete from t1;
|
|
|
|
insert into t1 values (3), (1);
|
|
|
|
|
|
|
|
insert into t1
|
|
|
|
select b from t2
|
|
|
|
where exists (select c from t3
|
|
|
|
group by (select * from (select a from t1) dt where a = 1));
|
|
|
|
select * from t1;
|
|
|
|
|
|
|
|
delete from t1;
|
|
|
|
insert into t1 values (3), (1);
|
|
|
|
|
|
|
|
prepare stmt from "
|
|
|
|
insert into t1
|
|
|
|
select b from t2
|
|
|
|
where b in (select c from t3
|
|
|
|
group by (select * from (select a from t1) dt where a = 1));
|
|
|
|
";
|
|
|
|
|
|
|
|
execute stmt;
|
|
|
|
select * from t1;
|
|
|
|
|
|
|
|
delete from t1;
|
|
|
|
insert into t1 values (3), (1);
|
|
|
|
|
|
|
|
execute stmt;
|
|
|
|
select * from t1;
|
|
|
|
|
|
|
|
delete from t1;
|
|
|
|
insert into t1 values (3), (1);
|
|
|
|
|
|
|
|
delete from t1
|
|
|
|
where exists (select b from t2
|
|
|
|
where b in (select c from t3
|
|
|
|
group by (select * from (select a from t1) dt
|
|
|
|
where a = 1)));
|
|
|
|
select * from t1;
|
|
|
|
|
|
|
|
deallocate prepare stmt;
|
|
|
|
|
|
|
|
drop table t1,t2,t3;
|
|
|
|
|
|
|
|
--echo # End of 10.3 test
|