32
32
auto int not null auto_increment,
33
fld1 int DEFAULT '000000' NOT NULL,
34
companynr int DEFAULT '00' NOT NULL,
33
fld1 int(6) unsigned zerofill DEFAULT '000000' NOT NULL,
34
companynr tinyint(2) unsigned zerofill DEFAULT '00' NOT NULL,
35
35
fld3 char(30) DEFAULT '' NOT NULL,
36
36
fld4 char(35) DEFAULT '' NOT NULL,
37
37
fld5 char(35) DEFAULT '' NOT NULL,
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
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.
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;
1434
1425
select distinct fld3,count(*) from t2 group by companynr,fld3 limit 10;
1426
SET SQL_BIG_TABLES=1; # Force use of MyISAM
1435
1427
select distinct fld3,count(*) from t2 group by companynr,fld3 limit 10;
1428
SET SQL_BIG_TABLES=0;
1436
1429
select distinct fld3,repeat("a",length(fld3)),count(*) from t2 group by companynr,fld3 limit 100,10;
1451
1444
# Here the last fld3 is optimized away from the order by
1454
--replace_column 9 #
1455
1447
explain select t3.t2nr,fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by t3.t2nr,fld3;
1458
1450
# Some test with ORDER BY and limit
1461
--replace_column 9 #
1462
1453
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period;
1463
--replace_column 9 #
1464
1454
explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10;
1465
--replace_column 9 #
1466
1455
explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period limit 10;
1509
1496
# We need another table for join stuff..
1512
create temporary table t4 (
1513
companynr int NOT NULL default '00',
1500
companynr tinyint(2) unsigned zerofill NOT NULL default '00',
1514
1501
companyname char(30) NOT NULL default '',
1515
1502
PRIMARY KEY (companynr),
1516
1503
UNIQUE KEY companyname(companyname)
1517
) ENGINE=MyISAM COMMENT='companynames';
1504
) ENGINE=MyISAM MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames';
1519
1506
--disable_query_log
1520
1507
INSERT INTO t4 (companynr, companyname) VALUES (29,'company 1');
1554
1541
select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null;
1555
1542
select count(*) from t2 left join t4 using (companynr) where t4.companynr is not null;
1556
--replace_column 9 #
1557
1543
explain select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null;
1558
--replace_column 9 #
1559
1544
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr is null;
1561
1546
select companynr,companyname from t2 left join t4 using (companynr) where companynr is null;
1562
1547
select count(*) from t2 left join t4 using (companynr) where companynr is not null;
1563
--replace_column 9 #
1564
1548
explain select companynr,companyname from t2 left join t4 using (companynr) where companynr is null;
1565
--replace_column 9 #
1566
1549
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr is null;
1567
1550
delete from t2 where fld1=999999;
1570
1553
# Test left join optimization
1572
--replace_column 9 #
1573
1555
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0;
1574
--replace_column 9 #
1575
1556
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
1557
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
1559
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0;
1581
--replace_column 9 #
1582
1560
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0;
1583
--replace_column 9 #
1584
1561
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0;
1585
1562
# Following can't be optimized
1586
--replace_column 9 #
1587
1563
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
1564
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
1565
explain select t2.companynr,companyname from t4 left join t2 using (companynr) where ifnull(t2.companynr,1)>0;
1593
--replace_column 9 #
1594
1567
explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null;
1595
--replace_column 9 #
1596
1568
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
1569
explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0;
1642
1612
select companynr,count(*),sum(fld1) from t2 group by companynr;
1643
1613
select companynr,count(*) from t2 group by companynr order by companynr desc limit 5;
1644
1614
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
1615
explain extended select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>"";
1647
1616
select companynr,count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 group by companynr limit 3;
1648
1617
select companynr,t2nr,count(price),sum(price),min(price),max(price),avg(price) from t3 where companynr = 37 group by companynr,t2nr limit 10;
1674
1643
# Group with extra not group fields.
1677
select companynr,companyname from t4 group by 1;
1646
select companynr|0,companyname from t4 group by 1;
1678
1647
select t2.companynr,companyname,count(*) from t2,t4 where t2.companynr=t4.companynr group by t2.companynr order by companyname;
1679
1648
select t2.fld1,count(*) from t2,t3 where t2.fld1=158402 and t3.name=t2.fld3 group by t3.name;
1797
1763
show full columns from t2 from test like 'f%';
1798
1764
--replace_column 8 #
1799
1765
show full columns from t2 from test like 's%';
1800
--replace_column 7 #
1801
1766
show keys from t2;
1803
1768
drop table t4, t3, t2, t1;
1806
CREATE TEMPORARY TABLE t1 (
1807
cont_nr int NOT NULL auto_increment,
1808
ver_nr int NOT NULL default '0',
1809
aufnr int NOT NULL default '0',
1772
cont_nr int(11) NOT NULL auto_increment,
1773
ver_nr int(11) NOT NULL default '0',
1774
aufnr int(11) NOT NULL default '0',
1810
1775
username varchar(50) NOT NULL default '',
1811
hdl_nr int NOT NULL default '0',
1776
hdl_nr int(11) NOT NULL default '0',
1777
eintrag date NOT NULL default '0000-00-00',
1813
1778
st_klasse varchar(40) NOT NULL default '',
1814
1779
st_wert varchar(40) NOT NULL default '',
1815
1780
st_zusatz varchar(40) NOT NULL default '',
1816
1781
st_bemerkung varchar(255) NOT NULL default '',
1817
1782
kunden_art varchar(40) NOT NULL default '',
1818
mcbs_knr int default NULL,
1819
mcbs_aufnr int NOT NULL default '0',
1783
mcbs_knr int(11) default NULL,
1784
mcbs_aufnr int(11) NOT NULL default '0',
1820
1785
schufa_status char(1) default '?',
1821
1786
bemerkung text,
1823
wf_igz int NOT NULL default '0',
1788
wf_igz int(11) NOT NULL default '0',
1824
1789
tarifcode varchar(80) default NULL,
1825
1790
recycle char(1) default NULL,
1826
1791
sim varchar(30) default NULL,
1827
1792
mcbs_tpl varchar(30) default NULL,
1828
emp_nr int NOT NULL default '0',
1829
laufzeit int default NULL,
1793
emp_nr int(11) NOT NULL default '0',
1794
laufzeit int(11) default NULL,
1830
1795
hdl_name varchar(30) default NULL,
1831
prov_hdl_nr int NOT NULL default '0',
1796
prov_hdl_nr int(11) NOT NULL default '0',
1832
1797
auto_wirknetz varchar(50) default NULL,
1833
1798
auto_billing varchar(50) default NULL,
1834
1799
touch timestamp NOT NULL,