mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 20:12:31 +01:00
ae5bc05988
create table t1 (a smallint primary key auto_increment); insert into t1 values(32767); insert into t1 values(NULL); ERROR 1062 (23000): Duplicate entry '32767' for key 'PRIMARY Now on always gets error HA_ERR_AUTOINC_RANGE=167 "Out of range value for column", independent of store engine, SQL Mode or number of inserted rows. This is an unique error that is easier to test for in replication. Another bug fix is that we now get an error when trying to insert a too big auto-generated value, even in non-strict mode. Before one get insted the max column value inserted. This patch also fixes some issues with inserting negative numbers in an auto-increment column. Fixed the ER_DUP_ENTRY and HA_ERR_AUTOINC_ERANGE are compared the same between master and slave. This ensures that replication works between an old server to a new slave for auto-increment overflow errors. Added SQLSTATE errors for handler errors Smaller bug fixes: * Added warnings for duplicate key errors when using INSERT IGNORE * Fixed bug when using --skip-log-bin followed by --log-bin, which did set log-bin to "0" * Allow one to see how cmake is called by using --just-print --just-configure BUILD/FINISH.sh: --just-print --just-configure now shows how cmake would be invoked. Good for understanding parameters to cmake. cmake/configure.pl: --just-print --just-configure now shows how cmake would be invoked. Good for understanding parameters to cmake. include/CMakeLists.txt: Added handler_state.h include/handler_state.h: SQLSTATE for handler error messages. Required for HA_ERR_AUTOINC_ERANGE, but solves also some other cases. mysql-test/extra/binlog_tests/binlog.test: Fixed old wrong behaviour Added more tests mysql-test/extra/binlog_tests/binlog_insert_delayed.test: Reset binary log to only print what's necessary in show_binlog_events mysql-test/extra/rpl_tests/rpl_auto_increment.test: Update to new error codes mysql-test/extra/rpl_tests/rpl_insert_delayed.test: Ignore warnings as this depends on how the test is run mysql-test/include/strict_autoinc.inc: On now gets an error on overflow mysql-test/r/auto_increment.result: Update results after fixing error message mysql-test/r/auto_increment_ranges_innodb.result: Test new behaviour mysql-test/r/auto_increment_ranges_myisam.result: Test new behaviour mysql-test/r/commit_1innodb.result: Added warnings for duplicate key error mysql-test/r/create.result: Added warnings for duplicate key error mysql-test/r/insert.result: Added warnings for duplicate key error mysql-test/r/insert_select.result: Added warnings for duplicate key error mysql-test/r/insert_update.result: Added warnings for duplicate key error mysql-test/r/mix2_myisam.result: Added warnings for duplicate key error mysql-test/r/myisam_mrr.result: Added warnings for duplicate key error mysql-test/r/null_key.result: Added warnings for duplicate key error mysql-test/r/replace.result: Update to new error codes mysql-test/r/strict_autoinc_1myisam.result: Update to new error codes mysql-test/r/strict_autoinc_2innodb.result: Update to new error codes mysql-test/r/strict_autoinc_3heap.result: Update to new error codes mysql-test/r/trigger.result: Added warnings for duplicate key error mysql-test/r/xtradb_mrr.result: Added warnings for duplicate key error mysql-test/suite/binlog/r/binlog_innodb_row.result: Updated result mysql-test/suite/binlog/r/binlog_row_binlog.result: Out of range data for auto-increment is not inserted anymore mysql-test/suite/binlog/r/binlog_statement_insert_delayed.result: Updated result mysql-test/suite/binlog/r/binlog_stm_binlog.result: Out of range data for auto-increment is not inserted anymore mysql-test/suite/binlog/r/binlog_unsafe.result: Updated result mysql-test/suite/innodb/r/innodb-autoinc.result: Update to new error codes mysql-test/suite/innodb/r/innodb-lock.result: Updated results mysql-test/suite/innodb/r/innodb.result: Updated results mysql-test/suite/innodb/r/innodb_bug56947.result: Updated results mysql-test/suite/innodb/r/innodb_mysql.result: Updated results mysql-test/suite/innodb/t/innodb-autoinc.test: Update to new error codes mysql-test/suite/maria/maria3.result: Updated result mysql-test/suite/maria/mrr.result: Updated result mysql-test/suite/optimizer_unfixed_bugs/r/bug43617.result: Updated result mysql-test/suite/rpl/r/rpl_auto_increment.result: Update to new error codes mysql-test/suite/rpl/r/rpl_insert_delayed,stmt.rdiff: Updated results mysql-test/suite/rpl/r/rpl_loaddatalocal.result: Updated results mysql-test/t/auto_increment.test: Update to new error codes mysql-test/t/auto_increment_ranges.inc: Test new behaviour mysql-test/t/auto_increment_ranges_innodb.test: Test new behaviour mysql-test/t/auto_increment_ranges_myisam.test: Test new behaviour mysql-test/t/replace.test: Update to new error codes mysys/my_getopt.c: Fixed bug when using --skip-log-bin followed by --log-bin, which did set log-bin to "0" sql/handler.cc: Ignore negative values for signed auto-increment columns Always give an error if we get an overflow for an auto-increment-column (instead of inserting the max value) Ensure that the row number is correct for the out-of-range-value error message. ****** Fixed wrong printing of column namn for "Out of range value" errors Fixed that INSERT_ID is correctly replicated also for out-of-range autoincrement values Fixed that print_keydup_error() can also be used to generate warnings ****** Return HA_ERR_AUTOINC_ERANGE (167) instead of ER_WARN_DATA_OUT_OF_RANGE for auto-increment overflow sql/handler.h: Allow INSERT IGNORE to continue also after out-of-range inserts. Fixed that print_keydup_error() can also be used to generate warnings sql/log_event.cc: Added DBUG_PRINT Fixed the ER_AUTOINC_READ_FAILED, ER_DUP_ENTRY and HA_ERR_AUTOINC_ERANGE are compared the same between master and slave. This ensures that replication works between an old server to a new slave for auto-increment overflow errors. sql/sql_insert.cc: Add warnings for duplicate key errors when using INSERT IGNORE sql/sql_state.c: Added handler errors sql/sql_table.cc: Update call to print_keydup_error() storage/innobase/handler/ha_innodb.cc: Fixed increment handling of auto-increment columns to be consistent with rest of MariaDB. storage/xtradb/handler/ha_innodb.cc: Fixed increment handling of auto-increment columns to be consistent with rest of MariaDB.
855 lines
14 KiB
Text
855 lines
14 KiB
Text
drop table if exists t1,t2,t3;
|
|
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;
|
|
insert into t2 (payoutID) SELECT payoutID+10 FROM t1;
|
|
ERROR 23000: Duplicate entry '16' for key 'PRIMARY'
|
|
insert ignore into t2 (payoutID) SELECT payoutID+10 FROM t1;
|
|
Warnings:
|
|
Warning 1062 Duplicate entry '16' for key 'PRIMARY'
|
|
Warning 1062 Duplicate entry '16' for key 'PRIMARY'
|
|
Warning 1062 Duplicate entry '22' for key 'PRIMARY'
|
|
select * from t2;
|
|
payoutID
|
|
1
|
|
4
|
|
6
|
|
9
|
|
10
|
|
11
|
|
12
|
|
14
|
|
16
|
|
19
|
|
20
|
|
22
|
|
drop table t1,t2;
|
|
CREATE TABLE `t1` (
|
|
`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`)
|
|
) ENGINE=MyISAM;
|
|
CREATE TABLE `t2` (
|
|
`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`)
|
|
) ENGINE=MyISAM;
|
|
INSERT INTO t2
|
|
(numeropost,icone,numreponse,contenu,pseudo,date,ip,signature) VALUES
|
|
(9,1,56,'test','joce','2001-07-25 13:50:53'
|
|
,3649052399,0);
|
|
INSERT INTO t1 (numeropost,icone,contenu,pseudo,date,signature,ip)
|
|
SELECT 1618,icone,contenu,pseudo,date,signature,ip FROM t2
|
|
WHERE numeropost=9 ORDER BY numreponse ASC;
|
|
show variables like '%bulk%';
|
|
Variable_name Value
|
|
bulk_insert_buffer_size 8388608
|
|
INSERT INTO t1 (numeropost,icone,contenu,pseudo,date,signature,ip)
|
|
SELECT 1718,icone,contenu,pseudo,date,signature,ip FROM t2
|
|
WHERE numeropost=9 ORDER BY numreponse ASC;
|
|
DROP TABLE t1,t2;
|
|
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;
|
|
a
|
|
1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
insert into t1 select * from t1 as t2;
|
|
select * from t1;
|
|
a
|
|
1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
insert into t2 select * from t1 as t2;
|
|
select * from t1;
|
|
a
|
|
1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
insert into t1 select t2.a from t1,t2;
|
|
select * from t1;
|
|
a
|
|
1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
1
|
|
2
|
|
2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
|
4
|
|
4
|
|
4
|
|
4
|
|
4
|
|
4
|
|
4
|
|
4
|
|
4
|
|
4
|
|
4
|
|
4
|
|
4
|
|
4
|
|
4
|
|
4
|
|
4
|
|
5
|
|
5
|
|
5
|
|
5
|
|
5
|
|
5
|
|
5
|
|
5
|
|
5
|
|
5
|
|
5
|
|
5
|
|
5
|
|
5
|
|
5
|
|
5
|
|
5
|
|
5
|
|
5
|
|
5
|
|
insert into t1 select * from t1,t1;
|
|
ERROR 42000: Not unique table/alias: 't1'
|
|
drop table t1,t2;
|
|
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");
|
|
insert into t1 select * from t2;
|
|
ERROR 23000: Duplicate entry '3' for key 'PRIMARY'
|
|
select * from t1;
|
|
a b
|
|
1 t1:1
|
|
3 t1:3
|
|
2 t2:2
|
|
replace into t1 select * from t2;
|
|
select * from t1;
|
|
a b
|
|
1 t1:1
|
|
2 t2:2
|
|
3 t2:3
|
|
drop table t1,t2;
|
|
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;
|
|
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;
|
|
Month Type Field Count
|
|
2003-09-01 1 1 100
|
|
2003-09-01 1 2 100
|
|
2003-09-01 2 1 100
|
|
2003-09-01 2 2 100
|
|
2003-09-01 3 1 100
|
|
Select null, Field, Count From t1 Where Month=20030901 and Type=2;
|
|
NULL Field Count
|
|
NULL 1 100
|
|
NULL 2 100
|
|
create table t2(No int not null, Field int not null, Count int not null);
|
|
insert into t2 Select null, Field, Count From t1 Where Month=20030901 and Type=2;
|
|
Warnings:
|
|
Warning 1048 Column 'No' cannot be null
|
|
Warning 1048 Column 'No' cannot be null
|
|
select * from t2;
|
|
No Field Count
|
|
0 1 100
|
|
0 2 100
|
|
drop table t1, t2;
|
|
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);
|
|
ID NO SEQ
|
|
1 1 1
|
|
drop table t1;
|
|
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;
|
|
ff1 ff2
|
|
1 2
|
|
2 1
|
|
drop table t1, t2;
|
|
create table t1 (a int unique);
|
|
create table t2 (a int, b int);
|
|
create table t3 (c int, d int);
|
|
insert into t1 values (1),(2);
|
|
insert into t2 values (1,2);
|
|
insert into t3 values (1,6),(3,7);
|
|
select * from t1;
|
|
a
|
|
1
|
|
2
|
|
insert into t1 select a from t2 on duplicate key update a= t1.a + t2.b;
|
|
select * from t1;
|
|
a
|
|
2
|
|
3
|
|
insert into t1 select a+1 from t2 on duplicate key update t1.a= t1.a + t2.b+1;
|
|
select * from t1;
|
|
a
|
|
3
|
|
5
|
|
insert into t1 select t3.c from t3 on duplicate key update a= a + t3.d;
|
|
select * from t1;
|
|
a
|
|
1
|
|
5
|
|
10
|
|
insert into t1 select t2.a from t2 group by t2.a on duplicate key update a= a + 10;
|
|
insert into t1 select t2.a from t2 on duplicate key update a= a + t2.b;
|
|
ERROR 23000: Column 'a' in field list is ambiguous
|
|
insert into t1 select t2.a from t2 on duplicate key update t2.a= a + t2.b;
|
|
ERROR 42S22: Unknown column 't2.a' in 'field list'
|
|
insert into t1 select t2.a from t2 group by t2.a on duplicate key update a= t1.a + t2.b;
|
|
ERROR 42S22: Unknown column 't2.b' in 'field list'
|
|
drop table t1,t2,t3;
|
|
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;
|
|
f1
|
|
2000
|
|
2001
|
|
2002
|
|
drop table t1;
|
|
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);
|
|
insert into t1(x,y) select x,z from t2 on duplicate key update x=values(z);
|
|
ERROR 42S22: Unknown column 'z' in 'field list'
|
|
insert into t1(x,y) select x,z from t2 on duplicate key update x=values(t2.x);
|
|
ERROR 42S22: Unknown column 't2.x' in 'field list'
|
|
drop table t1,t2;
|
|
CREATE TABLE t1 (a int PRIMARY KEY);
|
|
INSERT INTO t1 values (1), (2);
|
|
flush status;
|
|
INSERT INTO t1 SELECT a + 2 FROM t1 LIMIT 1;
|
|
show status like 'Handler_read%';
|
|
Variable_name Value
|
|
Handler_read_first 1
|
|
Handler_read_key 0
|
|
Handler_read_last 0
|
|
Handler_read_next 0
|
|
Handler_read_prev 0
|
|
Handler_read_rnd 0
|
|
Handler_read_rnd_deleted 0
|
|
Handler_read_rnd_next 1
|
|
DROP TABLE t1;
|
|
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;
|
|
COUNT(*)
|
|
1
|
|
SELECT min(t2.f1) FROM t1, t2 where t2.f2 = 'SIR' GROUP BY t1.f1;
|
|
min(t2.f1)
|
|
INSERT INTO t1 (f2)
|
|
SELECT min(t2.f1) FROM t1, t2 where t2.f2 = 'SIR' GROUP BY t1.f1;
|
|
SELECT COUNT(*) FROM t1;
|
|
COUNT(*)
|
|
1
|
|
SELECT * FROM t1;
|
|
f1 f2
|
|
1
|
|
DROP TABLE t1, t2;
|
|
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;
|
|
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;
|
|
USE test;
|
|
create table t1(f1 int primary key, f2 int);
|
|
insert into t1 values (1,1);
|
|
affected rows: 1
|
|
insert into t1 values (1,1) on duplicate key update f2=1;
|
|
affected rows: 0
|
|
insert into t1 values (1,1) on duplicate key update f2=2;
|
|
affected rows: 2
|
|
select * from t1;
|
|
f1 f2
|
|
1 2
|
|
drop table t1;
|
|
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;
|
|
SELECT * FROM t2;
|
|
f1 f2
|
|
10 10
|
|
101 1
|
|
2 2
|
|
DROP TABLE t1, t2;
|
|
CREATE TABLE t1 ( a INT KEY, b INT );
|
|
INSERT INTO t1 VALUES ( 0, 1 );
|
|
INSERT INTO t1 ( b ) SELECT MAX( b ) FROM t1 WHERE b = 2;
|
|
ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
|
|
DROP TABLE t1;
|
|
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;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 PRIMARY t1 ALL NULL NULL NULL NULL 2
|
|
2 SUBQUERY t1 ref ix_c ix_c 13 const 1 Using where
|
|
SELECT (SELECT SUM(LENGTH(c)) FROM t1 WHERE c='13_characters') FROM t1;
|
|
(SELECT SUM(LENGTH(c)) FROM t1 WHERE c='13_characters')
|
|
13
|
|
13
|
|
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;
|
|
d
|
|
13
|
|
13
|
|
7
|
|
7
|
|
20
|
|
20
|
|
DROP TABLE t1,t2;
|
|
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;
|
|
id prev_id join_id
|
|
1 NULL 0
|
|
2 1 0
|
|
3 2 0
|
|
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;
|
|
id prev_id join_id
|
|
1 NULL 0
|
|
2 1 0
|
|
3 2 0
|
|
4 3 0
|
|
DROP TABLE t1,t2;
|
|
#
|
|
# Bug#30384: Having SQL_BUFFER_RESULT option in the
|
|
# CREATE .. KEY(..) .. SELECT led to creating corrupted index.
|
|
#
|
|
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;
|
|
Table Op Msg_type Msg_text
|
|
test.t2 check status OK
|
|
drop table t1,t2;
|
|
End of 5.0 tests
|
|
##################################################################
|
|
#
|
|
# Bug #46075: Assertion failed: 0, file .\protocol.cc, line 416
|
|
#
|
|
CREATE TABLE t1(a INT);
|
|
SET max_heap_table_size = 16384;
|
|
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);
|
|
call mtr.add_suppression("mysqld.*: The table '.*#sql.*' is full");
|
|
INSERT IGNORE INTO t1 SELECT t1.a FROM t1,t1 t2,t1 t3,t1 t4,t1 t5,t1 t6,t1 t7;
|
|
SET GLOBAL myisam_data_pointer_size = @old_myisam_data_pointer_size;
|
|
DROP TABLE t1;
|
|
End of 5.1 tests
|