1285
1285
# Test using INDEX and IGNORE INDEX
1288
--replace_column 9 #
1288
1289
explain select t2.fld3 from t2 where fld3 = 'honeysuckle';
1291
--replace_column 9 #
1290
1292
explain select fld3 from t2 ignore index (fld3) where fld3 = 'honeysuckle';
1293
--replace_column 9 #
1291
1294
explain select fld3 from t2 use index (fld1) where fld3 = 'honeysuckle';
1296
--replace_column 9 #
1293
1297
explain select fld3 from t2 use index (fld3) where fld3 = 'honeysuckle';
1298
--replace_column 9 #
1294
1299
explain select fld3 from t2 use index (fld1,fld3) where fld3 = 'honeysuckle';
1328
1334
select fld1 from t2 where fld1=250501 or fld1="250502";
1335
--replace_column 9 #
1329
1336
explain select fld1 from t2 where fld1=250501 or fld1="250502";
1330
1337
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 #
1331
1339
explain select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502;
1351
1359
select distinct companynr from t2;
1352
1360
select distinct companynr from t2 order by companynr;
1353
1361
select distinct companynr from t2 order by companynr desc;
1354
select distinct t2.fld3,period from t2,t1 where companynr=37 and fld3 like "O%";
1362
select distinct t2.fld3,period from t2,t1 where companynr=37 and fld3 like "O%" ORDER BY t2.fld3,period;
1356
1364
select distinct fld3 from t2 where companynr = 34 order by fld3;
1357
select distinct fld3 from t2 limit 10;
1365
select distinct fld3 from t2 ORDER BY fld3 limit 10;
1358
1366
select distinct fld3 from t2 having fld3 like "A%" limit 10;
1359
1367
select distinct substring(fld3,1,3) from t2 where fld3 like "A%";
1360
select distinct substring(fld3,1,3) as a from t2 having a like "A%" order by a limit 10;
1368
select distinct lower(substring(fld3,1,3)) as a from t2 having a like "A%" order by a limit 10;
1361
1369
select distinct substring(fld3,1,3) from t2 where fld3 like "A%" limit 10;
1362
select distinct substring(fld3,1,3) as a from t2 having a like "A%" limit 10;
1364
1371
# make a big table.
1371
1378
price2 double(11,0),
1376
1383
--disable_query_log
1377
1385
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1001,"Iranizes",37,5987435,234724);
1378
1386
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1002,"violinist",37,28357832,8723648);
1379
1387
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1003,"extramarital",37,39654943,235872);
1384
1392
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1008,"tucked",311,234298,3275892);
1385
1393
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1009,"gems",447,2374834,9872392);
1386
1394
INSERT INTO t3 (period,name,companynr,price,price2) VALUES (1010,"clinker",512,786542,76234234);
1387
1396
--enable_query_log
1389
1398
create temporary table tmp engine = myisam select * from t3;
1442
1451
# Here the last fld3 is optimized away from the order by
1454
--replace_column 9 #
1445
1455
explain select t3.t2nr,fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by t3.t2nr,fld3;
1448
1458
# Some test with ORDER BY and limit
1461
--replace_column 9 #
1451
1462
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period;
1463
--replace_column 9 #
1452
1464
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10;
1465
--replace_column 9 #
1453
1466
explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period limit 10;
1468
1481
select fld3,period from t2,t3 where t2.fld1 = 011401 and t2.fld1=t3.t2nr and t3.period=1001;
1483
--replace_column 9 #
1470
1484
explain select fld3,period from t2,t3 where t2.fld1 = 011401 and t3.t2nr=t2.fld1 and 1001 = t3.period;
1473
1487
# Search with a constant table and several rows from another table
1476
1491
select fld3,period from t2,t1 where companynr*10 = 37*10;
1494
1509
# We need another table for join stuff..
1512
create temporary table t4 (
1498
1513
companynr int NOT NULL default '00',
1499
1514
companyname char(30) NOT NULL default '',
1500
1515
PRIMARY KEY (companynr),
1539
1554
select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null;
1540
1555
select count(*) from t2 left join t4 using (companynr) where t4.companynr is not null;
1556
--replace_column 9 #
1541
1557
explain select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null;
1558
--replace_column 9 #
1542
1559
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr is null;
1544
1561
select companynr,companyname from t2 left join t4 using (companynr) where companynr is null;
1545
1562
select count(*) from t2 left join t4 using (companynr) where companynr is not null;
1563
--replace_column 9 #
1546
1564
explain select companynr,companyname from t2 left join t4 using (companynr) where companynr is null;
1565
--replace_column 9 #
1547
1566
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr is null;
1548
1567
delete from t2 where fld1=999999;
1551
1570
# Test left join optimization
1572
--replace_column 9 #
1553
1573
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0;
1574
--replace_column 9 #
1554
1575
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0;
1576
--replace_column 9 #
1555
1577
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 and t4.companynr > 0;
1579
--replace_column 9 #
1557
1580
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0;
1581
--replace_column 9 #
1558
1582
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0;
1583
--replace_column 9 #
1559
1584
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0;
1560
1585
# Following can't be optimized
1586
--replace_column 9 #
1561
1587
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 #
1562
1589
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 #
1563
1591
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where ifnull(t2.companynr,1)>0;
1593
--replace_column 9 #
1565
1594
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null;
1595
--replace_column 9 #
1566
1596
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0 or companynr > 0;
1597
--replace_column 9 #
1567
1598
explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0;
1610
1642
select companynr,count(*),sum(fld1) from t2 group by companynr;
1611
1643
select companynr,count(*) from t2 group by companynr order by companynr desc limit 5;
1612
1644
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 #
1613
1646
explain extended select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>"";
1614
1647
select companynr,count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 group by companynr limit 3;
1615
1648
select companynr,t2nr,count(price),sum(price),min(price),max(price),avg(price) from t3 where companynr = 37 group by companynr,t2nr limit 10;
1700
1733
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 #
1702
1736
explain select fld3 from t2 where 1>2 or 2>3;
1737
--replace_column 9 #
1703
1738
explain select fld3 from t2 where fld1=fld1;
1725
1760
select max(fld1) from t2 where fld1>= 098024;
1726
1761
select count(*) from t3 where price2=76234234;
1727
1762
select count(*) from t3 where companynr=512 and price2=76234234;
1763
--replace_column 9 #
1728
1764
explain select min(fld1),max(fld1),count(*) from t2;
1729
1765
# PS does correct pre-zero here. MySQL can't do it as it returns a number.
1730
1766
--disable_ps_protocol
1761
1797
show full columns from t2 from test like 'f%';
1762
1798
--replace_column 8 #
1763
1799
show full columns from t2 from test like 's%';
1800
--replace_column 7 #
1764
1801
show keys from t2;
1766
1803
drop table t4, t3, t2, t1;
1806
CREATE TEMPORARY TABLE t1 (
1770
1807
cont_nr int NOT NULL auto_increment,
1771
1808
ver_nr int NOT NULL default '0',
1772
1809
aufnr int NOT NULL default '0',