39
39
UNIQUE fld1 (fld1),
48
48
--disable_query_log
50
49
INSERT INTO t2 VALUES (1,000001,00,'Omaha','teethe','neat','');
51
50
INSERT INTO t2 VALUES (2,011401,37,'breaking','dreaded','Steinberg','W');
52
51
INSERT INTO t2 VALUES (3,011402,37,'Romans','scholastics','jarring','');
1246
1245
INSERT INTO t2 VALUES (1191,068504,00,'bonfire','corresponds','positively','');
1247
1246
INSERT INTO t2 VALUES (1192,068305,00,'Colombo','hardware','colicky','');
1248
1247
INSERT INTO t2 VALUES (1193,000000,00,'nondecreasing','implant','thrillingly','');
1250
1248
--enable_query_log
1285
1283
# Test using INDEX and IGNORE INDEX
1288
--replace_column 9 #
1289
1286
explain select t2.fld3 from t2 where fld3 = 'honeysuckle';
1291
--replace_column 9 #
1292
1288
explain select fld3 from t2 ignore index (fld3) where fld3 = 'honeysuckle';
1293
--replace_column 9 #
1294
1289
explain select fld3 from t2 use index (fld1) where fld3 = 'honeysuckle';
1296
--replace_column 9 #
1297
1291
explain select fld3 from t2 use index (fld3) where fld3 = 'honeysuckle';
1298
--replace_column 9 #
1299
1292
explain select fld3 from t2 use index (fld1,fld3) where fld3 = 'honeysuckle';
1334
1326
select fld1 from t2 where fld1=250501 or fld1="250502";
1335
--replace_column 9 #
1336
1327
explain select fld1 from t2 where fld1=250501 or fld1="250502";
1337
1328
select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502;
1338
--replace_column 9 #
1339
1329
explain select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502;
1359
1349
select distinct companynr from t2;
1360
1350
select distinct companynr from t2 order by companynr;
1361
1351
select distinct companynr from t2 order by companynr desc;
1362
select distinct t2.fld3,period from t2,t1 where companynr=37 and fld3 like "O%" ORDER BY t2.fld3,period;
1352
select distinct t2.fld3,period from t2,t1 where companynr=37 and fld3 like "O%";
1364
1354
select distinct fld3 from t2 where companynr = 34 order by fld3;
1365
select distinct fld3 from t2 ORDER BY fld3 limit 10;
1355
select distinct fld3 from t2 limit 10;
1366
1356
select distinct fld3 from t2 having fld3 like "A%" limit 10;
1367
1357
select distinct substring(fld3,1,3) from t2 where fld3 like "A%";
1368
select distinct lower(substring(fld3,1,3)) as a from t2 having a like "A%" order by a limit 10;
1358
select distinct substring(fld3,1,3) as a from t2 having a like "A%" order by a limit 10;
1369
1359
select distinct substring(fld3,1,3) from t2 where fld3 like "A%" limit 10;
1360
select distinct substring(fld3,1,3) as a from t2 having a like "A%" limit 10;
1371
1362
# make a big table.
1378
1369
price2 double(11,0),
1383
1374
--disable_query_log
1385
1375
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1001,"Iranizes",37,5987435,234724);
1386
1376
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1002,"violinist",37,28357832,8723648);
1387
1377
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1003,"extramarital",37,39654943,235872);
1392
1382
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1008,"tucked",311,234298,3275892);
1393
1383
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1009,"gems",447,2374834,9872392);
1394
1384
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1010,"clinker",512,786542,76234234);
1396
1385
--enable_query_log
1398
1387
create temporary table tmp engine = myisam select * from t3;
1451
1440
# Here the last fld3 is optimized away from the order by
1454
--replace_column 9 #
1455
1443
explain select t3.t2nr,fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by t3.t2nr,fld3;
1458
1446
# Some test with ORDER BY and limit
1461
--replace_column 9 #
1462
1449
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period;
1463
--replace_column 9 #
1464
1450
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10;
1465
--replace_column 9 #
1466
1451
explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period limit 10;
1481
1466
select fld3,period from t2,t3 where t2.fld1 = 011401 and t2.fld1=t3.t2nr and t3.period=1001;
1483
--replace_column 9 #
1484
1468
explain select fld3,period from t2,t3 where t2.fld1 = 011401 and t3.t2nr=t2.fld1 and 1001 = t3.period;
1487
1471
# Search with a constant table and several rows from another table
1491
1474
select fld3,period from t2,t1 where companynr*10 = 37*10;
1509
1492
# We need another table for join stuff..
1512
create temporary table t4 (
1513
1496
companynr int NOT NULL default '00',
1514
1497
companyname char(30) NOT NULL default '',
1515
1498
PRIMARY KEY (companynr),
1516
1499
UNIQUE KEY companyname(companyname)
1517
) ENGINE=MyISAM COMMENT='companynames';
1500
) ENGINE=MyISAM MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames';
1519
1502
--disable_query_log
1520
1503
INSERT INTO t4 (companynr, companyname) VALUES (29,'company 1');
1554
1537
select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null;
1555
1538
select count(*) from t2 left join t4 using (companynr) where t4.companynr is not null;
1556
--replace_column 9 #
1557
1539
explain select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null;
1558
--replace_column 9 #
1559
1540
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr is null;
1561
1542
select companynr,companyname from t2 left join t4 using (companynr) where companynr is null;
1562
1543
select count(*) from t2 left join t4 using (companynr) where companynr is not null;
1563
--replace_column 9 #
1564
1544
explain select companynr,companyname from t2 left join t4 using (companynr) where companynr is null;
1565
--replace_column 9 #
1566
1545
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr is null;
1567
1546
delete from t2 where fld1=999999;
1570
1549
# Test left join optimization
1572
--replace_column 9 #
1573
1551
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0;
1574
--replace_column 9 #
1575
1552
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0;
1576
--replace_column 9 #
1577
1553
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 and t4.companynr > 0;
1579
--replace_column 9 #
1580
1555
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0;
1581
--replace_column 9 #
1582
1556
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0;
1583
--replace_column 9 #
1584
1557
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0;
1585
1558
# Following can't be optimized
1586
--replace_column 9 #
1587
1559
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr is null;
1588
--replace_column 9 #
1589
1560
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0 or t4.companynr > 0;
1590
--replace_column 9 #
1591
1561
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where ifnull(t2.companynr,1)>0;
1593
--replace_column 9 #
1594
1563
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null;
1595
--replace_column 9 #
1596
1564
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0 or companynr > 0;
1597
--replace_column 9 #
1598
1565
explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0;
1642
1608
select companynr,count(*),sum(fld1) from t2 group by companynr;
1643
1609
select companynr,count(*) from t2 group by companynr order by companynr desc limit 5;
1644
1610
select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>"";
1645
--replace_column 9 #
1646
1611
explain extended select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>"";
1647
1612
select companynr,count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 group by companynr limit 3;
1648
1613
select companynr,t2nr,count(price),sum(price),min(price),max(price),avg(price) from t3 where companynr = 37 group by companynr,t2nr limit 10;
1733
1698
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;
1735
--replace_column 9 #
1736
1700
explain select fld3 from t2 where 1>2 or 2>3;
1737
--replace_column 9 #
1738
1701
explain select fld3 from t2 where fld1=fld1;
1760
1723
select max(fld1) from t2 where fld1>= 098024;
1761
1724
select count(*) from t3 where price2=76234234;
1762
1725
select count(*) from t3 where companynr=512 and price2=76234234;
1763
--replace_column 9 #
1764
1726
explain select min(fld1),max(fld1),count(*) from t2;
1765
1727
# PS does correct pre-zero here. MySQL can't do it as it returns a number.
1766
1728
--disable_ps_protocol
1797
1759
show full columns from t2 from test like 'f%';
1798
1760
--replace_column 8 #
1799
1761
show full columns from t2 from test like 's%';
1800
--replace_column 7 #
1801
1762
show keys from t2;
1803
1764
drop table t4, t3, t2, t1;
1806
CREATE TEMPORARY TABLE t1 (
1807
1768
cont_nr int NOT NULL auto_increment,
1808
1769
ver_nr int NOT NULL default '0',
1809
1770
aufnr int NOT NULL default '0',