~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysql-test/t/select.test

  • Committer: Monty Taylor
  • Date: 2008-07-01 14:33:36 UTC
  • mto: (28.1.12 backport_patch)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: monty@inaugust.com-20080701143336-8uihm7dhpu92rt0q
Somehow missed moving password.c. Duh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
--enable_warnings
14
14
 
15
15
CREATE TABLE t1 (
16
 
  Period int DEFAULT '0' NOT NULL,
17
 
  Varor_period int DEFAULT '0' NOT NULL
 
16
  Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL,
 
17
  Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL
18
18
);
19
19
 
20
20
INSERT INTO t1 VALUES (9410,9412);
29
29
 
30
30
CREATE TABLE t2 (
31
31
  auto int not null auto_increment,
32
 
  fld1 int DEFAULT '0' NOT NULL,
33
 
  companynr int DEFAULT '0' NOT NULL,
 
32
  fld1 int(6) unsigned zerofill DEFAULT '000000' NOT NULL,
 
33
  companynr tinyint(2) unsigned zerofill DEFAULT '00' NOT NULL,
34
34
  fld3 char(30) DEFAULT '' NOT NULL,
35
35
  fld4 char(35) DEFAULT '' NOT NULL,
36
36
  fld5 char(35) DEFAULT '' NOT NULL,
1282
1282
# Test using INDEX and IGNORE INDEX
1283
1283
#
1284
1284
 
1285
 
#explain select t2.fld3 from t2 where fld3 = 'honeysuckle';
1286
 
 
1287
 
#explain select fld3 from t2 ignore index (fld3) where fld3 = 'honeysuckle';
1288
 
#explain select fld3 from t2 use index (fld1) where fld3 = 'honeysuckle';
1289
 
 
1290
 
#explain select fld3 from t2 use index (fld3) where fld3 = 'honeysuckle';
1291
 
#explain select fld3 from t2 use index (fld1,fld3) where fld3 = 'honeysuckle';
 
1285
explain select t2.fld3 from t2 where fld3 = 'honeysuckle';
 
1286
 
 
1287
explain select fld3 from t2 ignore index (fld3) where fld3 = 'honeysuckle';
 
1288
explain select fld3 from t2 use index (fld1) where fld3 = 'honeysuckle';
 
1289
 
 
1290
explain select fld3 from t2 use index (fld3) where fld3 = 'honeysuckle';
 
1291
explain select fld3 from t2 use index (fld1,fld3) where fld3 = 'honeysuckle';
1292
1292
 
1293
1293
#
1294
1294
# NOTE NOTE NOTE
1295
1295
# The next should give an error
1296
1296
#
1297
1297
 
1298
 
#-- error 1176
1299
 
#explain select fld3 from t2 ignore index (fld3,not_used);
1300
 
#-- error 1176
1301
 
#explain select fld3 from t2 use index (not_used);
 
1298
-- error 1176
 
1299
explain select fld3 from t2 ignore index (fld3,not_used);
 
1300
-- error 1176
 
1301
explain select fld3 from t2 use index (not_used);
1302
1302
 
1303
1303
#
1304
1304
# Test sorting with a used key (there is no need for sorting)
1305
1305
#
1306
1306
 
1307
1307
select t2.fld3 from t2 where fld3 >= 'honeysuckle' and fld3 <= 'honoring' order by fld3;
1308
 
#explain select t2.fld3 from t2 where fld3 >= 'honeysuckle' and fld3 <= 'honoring' order by fld3;
 
1308
explain select t2.fld3 from t2 where fld3 >= 'honeysuckle' and fld3 <= 'honoring' order by fld3;
1309
1309
select fld1,fld3 from t2 where fld3="Colombo" or fld3 = "nondecreasing" order by fld3;
1310
1310
 
1311
1311
1323
1323
#
1324
1324
 
1325
1325
select fld1 from t2 where fld1=250501 or fld1="250502";
1326
 
#explain select fld1 from t2 where fld1=250501 or fld1="250502"; 
 
1326
explain select fld1 from t2 where fld1=250501 or fld1="250502"; 
1327
1327
select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502;
1328
 
#explain select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502;
 
1328
explain select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502;
1329
1329
 
1330
1330
#
1331
1331
# Search with a key with LIKE constant
1332
1332
# If the like starts with a certain letter key will be used.
1333
1333
#
1334
1334
 
1335
 
--sorted_result
1336
1335
select fld1,fld3 from t2 where companynr = 37 and fld3 like 'f%';
1337
1336
select fld3 from t2 where fld3 like "L%" and fld3 = "ok";
1338
1337
select fld3 from t2 where (fld3 like "C%" and fld3 = "Chantilly");
1349
1348
select distinct companynr from t2;
1350
1349
select distinct companynr from t2 order by companynr;
1351
1350
select distinct companynr from t2 order by companynr desc;
1352
 
--sorted_result
1353
1351
select distinct t2.fld3,period from t2,t1 where companynr=37 and fld3 like "O%";
1354
1352
 
1355
1353
select distinct fld3 from t2 where companynr = 34 order by fld3;
1356
 
# PBXT: because there is no ORDER BY with a LIMIT, these
1357
 
# statements return different results to those from innodb
1358
 
--sorted_result
1359
1354
select distinct fld3 from t2 limit 10;
1360
1355
select distinct fld3 from t2 having fld3 like "A%" limit 10;
1361
1356
select distinct substring(fld3,1,3) from t2 where fld3 like "A%";
1362
1357
select distinct substring(fld3,1,3) as a from t2 having a like "A%" order by a limit 10;
1363
1358
select distinct substring(fld3,1,3) from t2 where fld3 like "A%" limit 10;
1364
 
--sorted_result
1365
1359
select distinct substring(fld3,1,3) as a from t2 having a like "A%" limit 10;
1366
1360
 
1367
1361
# make a big table.
1449
1443
# Here the last fld3 is optimized away from the order by
1450
1444
#
1451
1445
 
1452
 
#explain select t3.t2nr,fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by t3.t2nr,fld3;
 
1446
explain select t3.t2nr,fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by t3.t2nr,fld3;
1453
1447
 
1454
1448
#
1455
1449
# Some test with ORDER BY and limit
1456
1450
#
1457
1451
 
1458
 
#explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period;
1459
 
#explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10;
1460
 
#explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period limit 10;
 
1452
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period;
 
1453
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10;
 
1454
explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period limit 10;
1461
1455
 
1462
1456
#
1463
1457
# Search with a constant table.
1474
1468
 
1475
1469
select fld3,period from t2,t3 where t2.fld1 = 011401 and t2.fld1=t3.t2nr and t3.period=1001;
1476
1470
 
1477
 
#explain select fld3,period from t2,t3 where t2.fld1 = 011401 and t3.t2nr=t2.fld1 and 1001 = t3.period;
 
1471
explain select fld3,period from t2,t3 where t2.fld1 = 011401 and t3.t2nr=t2.fld1 and 1001 = t3.period;
1478
1472
 
1479
1473
#
1480
1474
# Search with a constant table and several rows from another table
1481
1475
#
1482
1476
 
1483
 
--sorted_result
1484
1477
select fld3,period from t2,t1 where companynr*10 = 37*10;
1485
1478
 
1486
1479
#
1503
1496
#
1504
1497
 
1505
1498
create table t4 (
1506
 
  companynr int NOT NULL default '0',
 
1499
  companynr tinyint(2) unsigned zerofill NOT NULL default '00',
1507
1500
  companyname char(30) NOT NULL default '',
1508
1501
  PRIMARY KEY (companynr),
1509
1502
  UNIQUE KEY companyname(companyname)
1546
1539
 
1547
1540
select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null;
1548
1541
select count(*) from t2 left join t4 using (companynr) where t4.companynr is not null;
1549
 
#explain select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null;
1550
 
#explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr is null;
 
1542
explain select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null;
 
1543
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr is null;
1551
1544
 
1552
1545
select companynr,companyname from t2 left join t4 using (companynr) where companynr is null;
1553
1546
select count(*) from t2 left join t4 using (companynr) where companynr is not null;
1554
 
#explain select companynr,companyname from t2 left join t4 using (companynr) where companynr is null;
1555
 
#explain select companynr,companyname from t4 left join t2 using (companynr) where companynr is null;
 
1547
explain select companynr,companyname from t2 left join t4 using (companynr) where companynr is null;
 
1548
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr is null;
1556
1549
delete from t2 where fld1=999999;
1557
1550
 
1558
1551
#
1559
1552
# Test left join optimization
1560
1553
 
1561
 
#explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0;
1562
 
#explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0;
1563
 
#explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 and t4.companynr > 0;
1564
 
#
1565
 
#explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0;
1566
 
#explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0;
1567
 
#explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0;
1568
 
## Following can't be optimized
1569
 
#explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr is null;
1570
 
#explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0 or t4.companynr > 0;
1571
 
#explain select t2.companynr,companyname from t4 left join t2 using (companynr) where ifnull(t2.companynr,1)>0;
1572
 
#
1573
 
#explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null;
1574
 
#explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0 or companynr > 0;
1575
 
#explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0;
 
1554
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0;
 
1555
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0;
 
1556
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 and t4.companynr > 0;
 
1557
 
 
1558
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0;
 
1559
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0;
 
1560
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0;
 
1561
# Following can't be optimized
 
1562
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr is null;
 
1563
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0 or t4.companynr > 0;
 
1564
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where ifnull(t2.companynr,1)>0;
 
1565
 
 
1566
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null;
 
1567
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0 or companynr > 0;
 
1568
explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0;
1576
1569
 
1577
1570
#
1578
1571
# Joins with forms.
1579
1572
#
1580
1573
 
1581
1574
select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1;
1582
 
#explain select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1;
 
1575
explain select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1;
1583
1576
 
1584
1577
#
1585
1578
# Search using 'or' with the same referens group.
1618
1611
select companynr,count(*),sum(fld1) from t2 group by companynr;
1619
1612
select companynr,count(*) from t2 group by companynr order by companynr desc limit 5;
1620
1613
select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>"";
1621
 
#explain extended select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>"";
 
1614
explain extended select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>"";
1622
1615
select companynr,count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 group by companynr limit 3;
1623
1616
select companynr,t2nr,count(price),sum(price),min(price),max(price),avg(price) from t3 where companynr = 37 group by companynr,t2nr limit 10;
1624
1617
select /*! SQL_SMALL_RESULT */ companynr,t2nr,count(price),sum(price),min(price),max(price),avg(price) from t3 where companynr = 37 group by companynr,t2nr limit 10;
1649
1642
# Group with extra not group fields.
1650
1643
#
1651
1644
 
1652
 
select companynr,companyname from t4 group by 1;
 
1645
select companynr|0,companyname from t4 group by 1;
1653
1646
select t2.companynr,companyname,count(*) from t2,t4 where t2.companynr=t4.companynr group by t2.companynr order by companyname;
1654
1647
select t2.fld1,count(*) from t2,t3 where t2.fld1=158402 and t3.name=t2.fld3 group by t3.name;
1655
1648
 
1707
1700
 
1708
1701
select t2.fld1,sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 512 and t3.t2nr = 38008 and t2.fld1 = 38008 or t2.fld1 = t3.t2nr and t3.t2nr = 38008 and t2.fld1 = 38008 or t3.t2nr = t2.fld1 and t2.fld1 = 38008 group by t2.fld1;
1709
1702
 
1710
 
#explain select fld3 from t2 where 1>2 or 2>3;
1711
 
#explain select fld3 from t2 where fld1=fld1;
 
1703
explain select fld3 from t2 where 1>2 or 2>3;
 
1704
explain select fld3 from t2 where fld1=fld1;
1712
1705
 
1713
1706
#
1714
1707
# HAVING
1733
1726
select max(fld1) from t2 where fld1>= 098024;
1734
1727
select count(*) from t3 where price2=76234234;
1735
1728
select count(*) from t3 where companynr=512 and price2=76234234;
1736
 
#explain select min(fld1),max(fld1),count(*) from t2;
 
1729
explain select min(fld1),max(fld1),count(*) from t2;
1737
1730
# PS does correct pre-zero here. MySQL can't do it as it returns a number.
1738
1731
--disable_ps_protocol
1739
1732
select min(fld1),max(fld1),count(*) from t2;
1769
1762
show full columns from t2 from test like 'f%';
1770
1763
--replace_column 8 #
1771
1764
show full columns from t2 from test like 's%';
1772
 
#show keys from t2;
 
1765
show keys from t2;
1773
1766
 
1774
1767
drop table t4, t3, t2, t1;
1775
1768
 
1778
1771
#
1779
1772
 
1780
1773
CREATE TABLE t1 (
1781
 
  id bigint NOT NULL auto_increment,
 
1774
  id mediumint(8) unsigned NOT NULL auto_increment,
1782
1775
  pseudo varchar(35) NOT NULL default '',
1783
1776
  PRIMARY KEY  (id),
1784
1777
  UNIQUE KEY pseudo (pseudo)
1792
1785
# Test of bug with SUM(CASE...)
1793
1786
#
1794
1787
 
1795
 
CREATE TABLE t1 (gvid int default NULL,  hmid int default NULL,  volid int default NULL,  mmid int default NULL,  hdid int default NULL,  fsid int default NULL,  ctid int default NULL,  dtid int default NULL,  cost int default NULL,  performance int default NULL,  serialnumber bigint default NULL,  monitored int default '1',  removed int default '0',  target int default '0',  dt_modified timestamp NOT NULL,  name varchar(255) binary default NULL,  description varchar(255) default NULL,  UNIQUE KEY hmid (hmid,volid)) ENGINE=MyISAM;
 
1788
CREATE TABLE t1 (gvid int(10) unsigned default NULL,  hmid int(10) unsigned default NULL,  volid int(10) unsigned default NULL,  mmid int(10) unsigned default NULL,  hdid int(10) unsigned default NULL,  fsid int(10) unsigned default NULL,  ctid int(10) unsigned default NULL,  dtid int(10) unsigned default NULL,  cost int(10) unsigned default NULL,  performance int(10) unsigned default NULL,  serialnumber bigint(20) unsigned default NULL,  monitored tinyint(3) unsigned default '1',  removed tinyint(3) unsigned default '0',  target tinyint(3) unsigned default '0',  dt_modified timestamp NOT NULL,  name varchar(255) binary default NULL,  description varchar(255) default NULL,  UNIQUE KEY hmid (hmid,volid)) ENGINE=MyISAM;
1796
1789
INSERT INTO t1 VALUES (200001,2,1,1,100,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\E$',''),(200002,2,2,1,101,1,1,1,0,0,0,1,0,1,20020425060057,'\\\\ARKIVIO-TESTPDC\\C$',''),(200003,1,3,2,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1,0,1,20020425060427,'c:',NULL);
1797
 
CREATE TABLE t2 (  hmid int default NULL,  volid int default NULL,  sampletid int default NULL,  sampletime datetime default NULL,  samplevalue bigint default NULL,  KEY idx1 (hmid,volid,sampletid,sampletime)) ENGINE=MyISAM;
 
1790
CREATE TABLE t2 (  hmid int(10) unsigned default NULL,  volid int(10) unsigned default NULL,  sampletid smallint(5) unsigned default NULL,  sampletime datetime default NULL,  samplevalue bigint(20) unsigned default NULL,  KEY idx1 (hmid,volid,sampletid,sampletime)) ENGINE=MyISAM;
1798
1791
INSERT INTO t2 VALUES (1,3,10,'2002-06-01 08:00:00',35),(1,3,1010,'2002-06-01 12:00:01',35);
1799
1792
# Disable PS becasue we get more warnings from PS than from normal execution
1800
1793
--disable_ps_protocol
1808
1801
# Test of bigint comparision
1809
1802
#
1810
1803
 
1811
 
create table  t1 (  A_Id bigint NOT NULL default '0',  A_UpdateBy char(10) NOT NULL default '',  A_UpdateDate bigint NOT NULL default '0',  A_UpdateSerial int NOT NULL default '0',  other_types bigint NOT NULL default '0',  wss_type bigint NOT NULL default '0');
 
1804
create table  t1 (  A_Id bigint(20) NOT NULL default '0',  A_UpdateBy char(10) NOT NULL default '',  A_UpdateDate bigint(20) NOT NULL default '0',  A_UpdateSerial int(11) NOT NULL default '0',  other_types bigint(20) NOT NULL default '0',  wss_type bigint(20) NOT NULL default '0');
1812
1805
INSERT INTO t1 VALUES (102935998719055004,'brade',1029359987,2,102935229116544068,102935229216544093);
1813
1806
select wss_type from t1 where wss_type ='102935229216544106';
1814
1807
select wss_type from t1 where wss_type ='102935229216544105';
1838
1831
select * from (t1 as t2 left join t1 as t3 using (a)) straight_join t1;
1839
1832
select * from t1 straight_join (t1 as t2 left join t1 as t3 using (a));
1840
1833
# inner join on
1841
 
--sorted_result
1842
1834
select * from (t1 as t2 left join t1 as t3 using (a)) inner join t1 on t1.a>1;
1843
1835
select * from t1 inner join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
1844
1836
# inner join using
1867
1859
select * from (t1 as t2 left join t1 as t3 using (a)) natural join t1;
1868
1860
drop table t1;
1869
1861
 
1870
 
CREATE TABLE t1 (  aa char(2),  id int NOT NULL auto_increment,  t2_id int NOT NULL default '0',  PRIMARY KEY  (id),  KEY replace_id (t2_id)) ENGINE=MyISAM;
 
1862
CREATE TABLE t1 (  aa char(2),  id int(11) NOT NULL auto_increment,  t2_id int(11) NOT NULL default '0',  PRIMARY KEY  (id),  KEY replace_id (t2_id)) ENGINE=MyISAM;
1871
1863
INSERT INTO t1 VALUES ("1",8264,2506),("2",8299,2517),("3",8301,2518),("4",8302,2519),("5",8303,2520),("6",8304,2521),("7",8305,2522);
1872
 
CREATE TABLE t2 ( id int NOT NULL auto_increment,  PRIMARY KEY  (id)) ENGINE=MyISAM;
 
1864
CREATE TABLE t2 ( id int(11) NOT NULL auto_increment,  PRIMARY KEY  (id)) ENGINE=MyISAM;
1873
1865
INSERT INTO t2 VALUES (2517), (2518), (2519), (2520), (2521), (2522);
1874
1866
select * from t1, t2 WHERE t1.t2_id = t2.id and t1.t2_id > 0   order by t1.id   LIMIT 0, 5;
1875
1867
drop table t1,t2;
1887
1879
insert into t2 values (1);
1888
1880
insert into t4 values (1,1);
1889
1881
 
1890
 
#explain select * from t1 left join t2 on id1 = id2 left join t3 on id1 = id3 left join t4 on id3 = id4 where id2 = 1 or id4 = 1;
 
1882
explain select * from t1 left join t2 on id1 = id2 left join t3 on id1 = id3
 
1883
left join t4 on id3 = id4 where id2 = 1 or id4 = 1;
1891
1884
select * from t1 left join t2 on id1 = id2 left join t3 on id1 = id3
1892
1885
left join t4 on id3 = id4 where id2 = 1 or id4 = 1;
1893
1886
 
1917
1910
create table t2 (c integer,  d integer, index(c), index(d));
1918
1911
insert into t1 values (1,2), (2,2), (3,2), (4,2);
1919
1912
insert into t2 values (1,3), (2,3), (3,4), (4,4);
1920
 
#explain select * from t1 left join t2 on a=c where d in (4);
 
1913
explain select * from t1 left join t2 on a=c where d in (4);
1921
1914
select * from t1 left join t2 on a=c where d in (4);
1922
 
#explain select * from t1 left join t2 on a=c where d = 4;
 
1915
explain select * from t1 left join t2 on a=c where d = 4;
1923
1916
select * from t1 left join t2 on a=c where d = 4;
1924
1917
drop table t1, t2;
1925
1918
 
1928
1921
#
1929
1922
 
1930
1923
CREATE TABLE t1 (
1931
 
  i int NOT NULL default '0',
 
1924
  i int(11) NOT NULL default '0',
1932
1925
  c char(10) NOT NULL default '',
1933
1926
  PRIMARY KEY  (i),
1934
1927
  UNIQUE KEY c (c)
1975
1968
DROP TABLE t1;
1976
1969
 
1977
1970
#
1978
 
# Bug#7425 inconsistent sort order on columns result of substraction
 
1971
# Bug#7425 inconsistent sort order on unsigned columns result of substraction
1979
1972
#
1980
1973
 
1981
 
create table t1 (a int, b int);
 
1974
create table t1 (a int(11) unsigned, b int(11) unsigned);
1982
1975
insert into t1 values (1,0), (1,1), (1,2);
1983
1976
select a-b  from t1 order by 1;
1984
1977
select a-b , (a-b < 0)  from t1 order by 1;
1985
1978
select a-b as d, (a-b >= 0), b from t1 group by b having d >= 0;
1986
 
select a - b from t1 order by 1;
 
1979
select cast((a - b) as unsigned) from t1 order by 1;
1987
1980
drop table t1;
1988
1981
 
1989
1982
 
1990
1983
#
1991
1984
# Bug#8733 server accepts malformed query (multiply mentioned distinct)
1992
1985
#
1993
 
create table t1 (a int);
 
1986
create table t1 (a int(11));
1994
1987
select all all * from t1;
1995
1988
select distinct distinct * from t1;
1996
1989
--error 1221
2003
1996
# Test for BUG#10095
2004
1997
#
2005
1998
CREATE TABLE t1 (
2006
 
  kunde_intern_id int NOT NULL default '0',
2007
 
  kunde_id int NOT NULL default '0',
2008
 
  FK_firma_id int NOT NULL default '0',
 
1999
  kunde_intern_id int(10) unsigned NOT NULL default '0',
 
2000
  kunde_id int(10) unsigned NOT NULL default '0',
 
2001
  FK_firma_id int(10) unsigned NOT NULL default '0',
2009
2002
  aktuell enum('Ja','Nein') NOT NULL default 'Ja',
2010
2003
  vorname varchar(128) NOT NULL default '',
2011
2004
  nachname varchar(128) NOT NULL default '',
2061
2054
 
2062
2055
#
2063
2056
#
2064
 
# Test for Bug#8009, SELECT failed on bigint when using HEX
 
2057
# Test for Bug#8009, SELECT failed on bigint unsigned when using HEX
2065
2058
#
2066
2059
 
2067
 
CREATE TABLE t1 (b BIGINT NOT NULL, PRIMARY KEY (b));
2068
 
INSERT INTO t1 VALUES (0x4000000000000000);
2069
 
SELECT b FROM t1 WHERE b=0x4000000000000000;
 
2060
CREATE TABLE t1 (b BIGINT(20) UNSIGNED NOT NULL, PRIMARY KEY (b));
 
2061
INSERT INTO t1 VALUES (0x8000000000000000);
 
2062
SELECT b FROM t1 WHERE b=0x8000000000000000;
2070
2063
DROP TABLE t1;
2071
2064
 
2072
2065
#
2073
2066
# IN with outer join condition (BUG#9393)
2074
2067
#
2075
 
CREATE TABLE `t1` ( `gid` int default NULL, `uid` int default NULL);
 
2068
CREATE TABLE `t1` ( `gid` int(11) default NULL, `uid` int(11) default NULL);
2076
2069
 
2077
 
CREATE TABLE `t2` ( `ident` int default NULL, `level` char(16) default NULL);
 
2070
CREATE TABLE `t2` ( `ident` int(11) default NULL, `level` char(16) default NULL);
2078
2071
INSERT INTO `t2` VALUES (0,'READ');
2079
2072
 
2080
 
CREATE TABLE `t3` ( `id` int default NULL, `name` char(16) default NULL);
 
2073
CREATE TABLE `t3` ( `id` int(11) default NULL, `name` char(16) default NULL);
2081
2074
INSERT INTO `t3` VALUES (1,'fs');
2082
2075
 
2083
2076
select * from t3 left join t1 on t3.id = t1.uid, t2 where t2.ident in (0, t1.gid, t3.id, 0);
2086
2079
 
2087
2080
# Test for BUG#11700
2088
2081
CREATE TABLE t1 (
2089
 
  acct_id int NOT NULL default '0',
2090
 
  profile_id int default NULL,
 
2082
  acct_id int(11) NOT NULL default '0',
 
2083
  profile_id smallint(6) default NULL,
2091
2084
  UNIQUE KEY t1$acct_id (acct_id),
2092
2085
  KEY t1$profile_id (profile_id)
2093
2086
);
2094
2087
INSERT INTO t1 VALUES (132,17),(133,18);
2095
2088
 
2096
2089
CREATE TABLE t2 (
2097
 
  profile_id int default NULL,
2098
 
  queue_id int default NULL,
2099
 
  seq int default NULL,
 
2090
  profile_id smallint(6) default NULL,
 
2091
  queue_id int(11) default NULL,
 
2092
  seq int(11) default NULL,
2100
2093
  KEY t2$queue_id (queue_id)
2101
2094
);
2102
2095
INSERT INTO t2 VALUES (17,31,4),(17,30,3),(17,36,2),(17,37,1);
2103
2096
 
2104
2097
CREATE TABLE t3 (
2105
 
  id int NOT NULL default '0',
2106
 
  qtype int default NULL,
2107
 
  seq int default NULL,
2108
 
  warn_lvl int default NULL,
2109
 
  crit_lvl int default NULL,
2110
 
  rr1 int NOT NULL default '0',
2111
 
  rr2 int default NULL,
2112
 
  default_queue int NOT NULL default '0',
 
2098
  id int(11) NOT NULL default '0',
 
2099
  qtype int(11) default NULL,
 
2100
  seq int(11) default NULL,
 
2101
  warn_lvl int(11) default NULL,
 
2102
  crit_lvl int(11) default NULL,
 
2103
  rr1 tinyint(4) NOT NULL default '0',
 
2104
  rr2 int(11) default NULL,
 
2105
  default_queue tinyint(4) NOT NULL default '0',
2113
2106
  KEY t3$qtype (qtype),
2114
2107
  KEY t3$id (id)
2115
2108
);
2140
2133
# Bug #11521 Negative integer keys incorrectly substituted for 0 during
2141
2134
#            range analysis.
2142
2135
 
2143
 
create table t2 (a int);
 
2136
create table t2 (a tinyint unsigned);
2144
2137
create index t2i on t2(a);
2145
2138
insert into t2 values (0), (254), (255);
2146
 
#explain select * from t2 where a > -1;
 
2139
explain select * from t2 where a > -1;
2147
2140
select * from t2 where a > -1;
2148
2141
drop table t2;
2149
2142
 
2230
2223
CREATE TABLE t3 (a int, b int, PRIMARY KEY (a,b), KEY a (a), KEY b (b));
2231
2224
insert into t3 values (1,1),(1,2);
2232
2225
# must have "range checked" for t2
2233
 
#explain select straight_join DISTINCT t2.a,t2.b, t1.c from t1, t3, t2 where (t1.c=t2.a or (t1.c=t3.a and t2.a=t3.b)) and t1.b=556476786 and t2.b like '%%' order by t2.b limit 0,1;
 
2226
explain select straight_join DISTINCT t2.a,t2.b, t1.c from t1, t3, t2 
 
2227
 where (t1.c=t2.a or (t1.c=t3.a and t2.a=t3.b)) and t1.b=556476786 and 
 
2228
       t2.b like '%%' order by t2.b limit 0,1;
2234
2229
DROP TABLE t1,t2,t3;
2235
2230
 
2236
2231
#
2273
2268
INSERT INTO t1 VALUES (0.3762),(0.3845),(0.6158),(0.7941);
2274
2269
INSERT INTO t2 VALUES (1.3762),(1.3845),(1.6158),(1.7941);
2275
2270
 
2276
 
#explain select max(key1) from t1 where key1 <= 0.6158;
2277
 
#explain select max(key2) from t2 where key2 <= 1.6158;
2278
 
#explain select min(key1) from t1 where key1 >= 0.3762;
2279
 
#explain select min(key2) from t2 where key2 >= 1.3762;
2280
 
#explain select max(key1), min(key2) from t1, t2 where key1 <= 0.6158 and key2 >= 1.3762;
2281
 
#explain select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5;
2282
 
#explain select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5;
 
2271
explain select max(key1) from t1 where key1 <= 0.6158;
 
2272
explain select max(key2) from t2 where key2 <= 1.6158;
 
2273
explain select min(key1) from t1 where key1 >= 0.3762;
 
2274
explain select min(key2) from t2 where key2 >= 1.3762;
 
2275
explain select max(key1), min(key2) from t1, t2
 
2276
where key1 <= 0.6158 and key2 >= 1.3762;
 
2277
explain select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5;
 
2278
explain select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5;
2283
2279
 
2284
2280
select max(key1) from t1 where key1 <= 0.6158;
2285
2281
select max(key2) from t2 where key2 <= 1.6158;
2307
2303
# This test is here only to make sure that behavior is not changed in
2308
2304
# 4.1 and 5.0
2309
2305
#
2310
 
CREATE TABLE t1 (i BIGINT NOT NULL);
 
2306
CREATE TABLE t1 (i BIGINT UNSIGNED NOT NULL);
2311
2307
INSERT INTO t1 VALUES (10);
2312
2308
SELECT i='1e+01',i=1e+01, i in (1e+01,1e+01), i in ('1e+01','1e+01') FROM t1;
2313
2309
DROP TABLE t1;
2314
2310
 
2315
2311
#
2316
 
# Bug #32103: optimizer crash when join on int and bigint with variable in 
 
2312
# Bug #32103: optimizer crash when join on int and mediumint with variable in 
2317
2313
#             where clause
2318
2314
#
2319
2315
 
2340
2336
#
2341
2337
 
2342
2338
CREATE TABLE t1 ( 
2343
 
K2C4 varchar(4) collate utf8_bin NOT NULL default '', 
2344
 
K4N4 varchar(4) collate utf8_bin NOT NULL default '0000', 
2345
 
F2I4 int NOT NULL default '0' 
2346
 
) ENGINE=MyISAM;
 
2339
K2C4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '', 
 
2340
K4N4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '0000', 
 
2341
F2I4 int(11) NOT NULL default '0' 
 
2342
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
2347
2343
 
2348
2344
INSERT INTO t1 VALUES 
2349
2345
('W%RT', '0100',  1), 
2432
2428
#
2433
2429
# Bug #11398 Bug in field_conv() results in wrong result of join with index
2434
2430
#
2435
 
create table t1 (f1 varchar(6) default NULL, f2 int primary key not null);
 
2431
create table t1 (f1 varchar(6) default NULL, f2 int(6) primary key not null);
2436
2432
create table t2 (f3 varchar(5) not null, f4 varchar(5) not null, UNIQUE KEY UKEY (f3,f4));
2437
2433
insert into t1 values (" 2", 2);
2438
2434
insert into t2 values (" 2", " one "),(" 2", " two ");
2454
2450
#           incorrect transformation to join ... on.
2455
2451
#
2456
2452
 
2457
 
create table t1 (a int, t1_val int);
2458
 
create table t2 (b int, t2_val int);
2459
 
create table t3 (a int, b int);
 
2453
create table t1 (a int(10), t1_val int(10));
 
2454
create table t2 (b int(10), t2_val int(10));
 
2455
create table t3 (a int(10), b int(10));
2460
2456
insert into t1 values (1,1),(2,2);
2461
2457
insert into t2 values (1,1),(2,2),(3,3);
2462
2458
insert into t3 values (1,1),(2,1),(3,1),(4,1);
2483
2479
# for base tables, search all nested join operands of natural joins.
2484
2480
#
2485
2481
 
2486
 
CREATE TABLE t1 (`id` int);
2487
 
CREATE TABLE t2 (`id` int);
2488
 
CREATE TABLE t3 (`id` int);
 
2482
CREATE TABLE t1 (`id` TINYINT);
 
2483
CREATE TABLE t2 (`id` TINYINT);
 
2484
CREATE TABLE t3 (`id` TINYINT);
2489
2485
INSERT INTO t1 VALUES (1),(2),(3);
2490
2486
INSERT INTO t2 VALUES (2);
2491
2487
INSERT INTO t3 VALUES (3);
2504
2500
# Bug #13067 JOIN xxx USING is case sensitive
2505
2501
#
2506
2502
 
2507
 
create table t1 (a int,b int);
2508
 
create table t2 (a int,b int);
 
2503
create table t1 (a int(10),b int(10));
 
2504
create table t2 (a int(10),b int(10));
2509
2505
insert into t1 values (1,10),(2,20),(3,30);
2510
2506
insert into t2 values (1,10);
2511
2507
# both queries should produce the same result
2553
2549
# nested right join.
2554
2550
#
2555
2551
 
2556
 
create table t1 (id int not null default '0');
 
2552
create table t1 (id int(11) not null default '0');
2557
2553
insert into t1 values (123),(191),(192);
2558
 
create table t2 (id char(16) not null);
 
2554
create table t2 (id char(16) character set utf8 not null);
2559
2555
insert into t2 values ('58013'),('58014'),('58015'),('58016');
2560
 
create table t3 (a_id int not null, b_id char(16));
 
2556
create table t3 (a_id int(11) not null, b_id char(16) character set utf8);
2561
2557
insert into t3 values (123,null),(123,null),(123,null),(123,null),(123,null),(123,'58013');
2562
2558
 
2563
2559
# both queries are equivalent
2712
2708
 
2713
2709
DROP TABLE t1,t2;
2714
2710
 
 
2711
#
 
2712
# Bug#18712: Truncation problem (needs just documenting and test
 
2713
# cases to prevent fixing this accidently. It is intended behaviour)
 
2714
#
 
2715
 
 
2716
CREATE TABLE t1 (i TINYINT UNSIGNED NOT NULL);
 
2717
INSERT t1 SET i = 0;
 
2718
UPDATE t1 SET i = -1;
 
2719
SELECT * FROM t1;
 
2720
UPDATE t1 SET i = CAST(i - 1 AS SIGNED);
 
2721
SELECT * FROM t1;
 
2722
UPDATE t1 SET i = i - 1;
 
2723
SELECT * FROM t1;
 
2724
DROP TABLE t1;
 
2725
 
2715
2726
# BUG#17379
2716
2727
 
2717
2728
create table t1 (a int);
2721
2732
analyze table t2;
2722
2733
select 'In next EXPLAIN, B.rows must be exactly 10:' Z;
2723
2734
 
2724
 
#explain select * from t2 A, t2 B where A.a=5 and A.b=5 and A.C<5 and B.a=5 and B.b=A.e and (B.b =1 or B.b = 3 or B.b=5);
 
2735
explain select * from t2 A, t2 B where A.a=5 and A.b=5 and A.C<5
 
2736
          and B.a=5 and B.b=A.e and (B.b =1 or B.b = 3 or B.b=5);
2725
2737
drop table t1, t2;
2726
2738
 
2727
2739
#
2746
2758
DROP TABLE t1, t2;
2747
2759
 
2748
2760
#
2749
 
# Bug #18895: Now tests for int
 
2761
# Bug #18895: BIT values cause joins to fail
2750
2762
#
2751
2763
create table t1 (
2752
 
    a int    not null auto_increment primary key,
2753
 
    b int             not null,
2754
 
    c int             not null
 
2764
    a int unsigned    not null auto_increment primary key,
 
2765
    b bit             not null,
 
2766
    c bit             not null
2755
2767
);
2756
2768
 
2757
2769
create table t2 (
2758
 
    a int    not null auto_increment primary key,
2759
 
    b int             not null,
2760
 
    c int    not null,
 
2770
    a int unsigned    not null auto_increment primary key,
 
2771
    b bit             not null,
 
2772
    c int unsigned    not null,
2761
2773
    d varchar(50)
2762
2774
);
2763
2775
 
2983
2995
SELECT COUNT(*) FROM t1 WHERE ID1_with_null IS NULL AND ID2_with_null IS NULL;
2984
2996
SELECT COUNT(*) FROM t1 WHERE ID_better=1;
2985
2997
 
2986
 
# PBXT: does not return a consistent row count
2987
 
--replace_column 9 #
2988
2998
EXPLAIN SELECT * FROM t1
2989
2999
  WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ;
2990
 
--replace_column 9 #
2991
3000
EXPLAIN SELECT * FROM t1
2992
3001
  WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null=3 IS NULL ;
2993
 
--replace_column 9 #
2994
3002
EXPLAIN SELECT * FROM t1
2995
3003
  WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null IS NULL;
2996
3004
 
3031
3039
  AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31";
3032
3040
 
3033
3041
DROP TABLE t1,t2;
3034
 
# Bug #22026: Warning when using IF statement and large bigint
 
3042
# Bug #22026: Warning when using IF statement and large unsigned bigint
3035
3043
#
3036
3044
 
3037
 
create table t1 (a bigint);
 
3045
create table t1 (a bigint unsigned);
3038
3046
insert into t1 values
3039
 
  (if(1, 92233720368547758, 1)),
3040
 
  (case when 1 then 92233720368547758 else 1 end),
3041
 
  (coalesce(92233720368547758, 1));
 
3047
  (if(1, 9223372036854775808, 1)),
 
3048
  (case when 1 then 9223372036854775808 else 1 end),
 
3049
  (coalesce(9223372036854775808, 1));
3042
3050
select * from t1;
3043
3051
drop table t1;
3044
3052
create table t1 select
3049
3057
drop table t1;
3050
3058
# Ensure we handle big values properly
3051
3059
select 
3052
 
  if(1, 1111111111111111111, 1) i,
3053
 
  case when 1 then 1111111111111111111 else 1 end c,
3054
 
  coalesce(1111111111111111111, 1) co;
 
3060
  if(1, cast(1111111111111111111 as unsigned), 1) i,
 
3061
  case when 1 then cast(1111111111111111111 as unsigned) else 1 end c,
 
3062
  coalesce(cast(1111111111111111111 as unsigned), 1) co;
3055
3063
 
3056
3064
#
3057
3065
# Bug #22971: indexes on text columns are ignored for ref accesses 
3195
3203
#
3196
3204
 
3197
3205
CREATE TABLE t1 (
3198
 
  c1 int NOT NULL AUTO_INCREMENT,
 
3206
  c1 int(11) NOT NULL AUTO_INCREMENT,
3199
3207
  c2 varchar(1000) DEFAULT NULL,
3200
 
  c3 bigint DEFAULT NULL,
3201
 
  c4 bigint DEFAULT NULL,
 
3208
  c3 bigint(20) DEFAULT NULL,
 
3209
  c4 bigint(20) DEFAULT NULL,
3202
3210
  PRIMARY KEY (c1)
3203
3211
);
3204
3212
 
3264
3272
# Bug #30666: Incorrect order when using range conditions on 2 tables or more
3265
3273
#
3266
3274
 
3267
 
CREATE TABLE t1 (c11 INT NOT NULL AUTO_INCREMENT PRIMARY KEY);
3268
 
CREATE TABLE t2 (c21 INT NOT NULL, 
 
3275
CREATE TABLE t1 (c11 INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY);
 
3276
CREATE TABLE t2 (c21 INT UNSIGNED NOT NULL, 
3269
3277
                 c22 INT DEFAULT NULL, 
3270
3278
                 KEY(c21, c22));
3271
 
CREATE TABLE t3 (c31 INT NOT NULL DEFAULT 0, 
 
3279
CREATE TABLE t3 (c31 INT UNSIGNED NOT NULL DEFAULT 0, 
3272
3280
                 c32 INT DEFAULT NULL, 
3273
3281
                 c33 INT NOT NULL, 
3274
 
                 c34 INT DEFAULT 0,
 
3282
                 c34 INT UNSIGNED DEFAULT 0,
3275
3283
                 KEY (c33, c34, c32));
3276
3284
 
3277
3285
INSERT INTO t1 values (),(),(),(),();