home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 May (DVD) / Macworld Resource DVD May 2003.toast / Data / Software / Bonus / Database / mysql-max-3.23.55.sit / mysql-max-3.23.55-apple-darwi.1 / mysql-test / t / bdb.test < prev    next >
Encoding:
Text File  |  2003-01-21  |  22.9 KB  |  770 lines  |  [TEXT/ttxt]

  1. -- source include/have_bdb.inc
  2.  
  3. #
  4. # Small basic test with ignore
  5. #
  6.  
  7. drop table if exists t1,t2,t3,t4,t5,t6,t7,t8;
  8. create table t1 (id int unsigned not null auto_increment, code tinyint unsigned not null, name char(20) not null, primary key (id), key (code), unique (name)) type=bdb;
  9.  
  10. insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David'), (2, 'Erik'), (3, 'Sasha'), (3, 'Jeremy'), (4, 'Matt');
  11. select id, code, name from t1 order by id;
  12.  
  13. update ignore t1 set id = 8, name = 'Sinisa' where id < 3;
  14. select id, code, name from t1 order by id;
  15. update ignore t1 set id = id + 10, name = 'Ralph' where id < 4;
  16. select id, code, name from t1 order by id;
  17.  
  18. drop table t1;
  19.  
  20. #
  21. # A bit bigger test
  22. #
  23.  
  24. CREATE TABLE t1 (
  25.   id int(11) NOT NULL auto_increment,
  26.   parent_id int(11) DEFAULT '0' NOT NULL,
  27.   level tinyint(4) DEFAULT '0' NOT NULL,
  28.   PRIMARY KEY (id),
  29.   KEY parent_id (parent_id),
  30.   KEY level (level)
  31. ) type=bdb;
  32. INSERT INTO t1 VALUES (1,0,0),(3,1,1),(4,1,1),(8,2,2),(9,2,2),(17,3,2),(22,4,2),(24,4,2),(28,5,2),(29,5,2),(30,5,2),(31,6,2),(32,6,2),(33,6,2),(203,7,2),(202,7,2),(20,3,2),(157,0,0),(193,5,2),(40,7,2),(2,1,1),(15,2,2),(6,1,1),(34,6,2),(35,6,2),(16,3,2),(7,1,1),(36,7,2),(18,3,2),(26,5,2),(27,5,2),(183,4,2),(38,7,2),(25,5,2),(37,7,2),(21,4,2),(19,3,2),(5,1,1),(179,5,2);
  33. update t1 set parent_id=parent_id+100;
  34. select * from t1 where parent_id=102;
  35. update t1 set id=id+1000;
  36. -- error 1062
  37. update t1 set id=1024 where id=1009; 
  38. select * from t1;
  39. update ignore t1 set id=id+1; # This will change all rows
  40. select * from t1;
  41. update ignore t1 set id=1023 where id=1010;
  42. select * from t1 where parent_id=102;
  43. explain select level from t1 where level=1;
  44. explain select level,id from t1 where level=1;
  45. explain select level,id,parent_id from t1 where level=1;
  46. select level,id from t1 where level=1;
  47. select level,id,parent_id from t1 where level=1;
  48. optimize table t1;
  49. show keys from t1;
  50. drop table t1;
  51.  
  52. #
  53. # Test replace
  54. #
  55.  
  56. CREATE TABLE t1 (
  57.   gesuchnr int(11) DEFAULT '0' NOT NULL,
  58.   benutzer_id int(11) DEFAULT '0' NOT NULL,
  59.   PRIMARY KEY (gesuchnr,benutzer_id)
  60. ) type=BDB;
  61.  
  62. replace into t1 (gesuchnr,benutzer_id) values (2,1);
  63. replace into t1 (gesuchnr,benutzer_id) values (1,1);
  64. replace into t1 (gesuchnr,benutzer_id) values (1,1);
  65. select * from t1;
  66. drop table t1;
  67.  
  68. # test for bug in replace with secondary key
  69. create table t1 (id int not null primary key, x int not null, key (x)) type=bdb;
  70. insert into t1 (id, x) values (1, 1);
  71. replace into t1 (id, x) values (1, 2);
  72. select * from t1;
  73. drop table t1;
  74.  
  75. #
  76. # test delete using hidden_primary_key
  77. #
  78.  
  79. create table t1 (a int) type=bdb;
  80. insert into t1 values (1), (2);
  81. optimize table t1;
  82. delete from t1 where a = 1;
  83. select * from t1;
  84. check table t1;
  85. drop table t1;
  86.  
  87. create table t1 (a int,b varchar(20)) type=bdb;
  88. insert into t1 values (1,""), (2,"testing");
  89. delete from t1 where a = 1;
  90. select * from t1;
  91. create index skr on t1 (a);
  92. insert into t1 values (3,""), (4,"testing");
  93. analyze table t1;
  94. show keys from t1;
  95. drop table t1;
  96.  
  97. # Test of reading on secondary key with may be null
  98.  
  99. create table t1 (a int,b varchar(20),key(a)) type=bdb;
  100. insert into t1 values (1,""), (2,"testing");
  101. select * from t1 where a = 1;
  102. drop table t1;
  103.  
  104. #
  105. # Test auto_increment on sub key
  106. #
  107.  
  108. create table t1 (a char(10) not null, b int not null auto_increment, primary key(a,b)) type=BDB;
  109. insert into t1 values ("a",1),("b",2),("a",2),("c",1);
  110. insert into t1 values ("a",NULL),("b",NULL),("c",NULL),("e",NULL);
  111. insert into t1 (a) values ("a"),("b"),("c"),("d");
  112. insert into t1 (a) values ('k'),('d');
  113. insert into t1 (a) values ("a");
  114. insert into t1 values ("d",last_insert_id());
  115. select * from t1;
  116. flush tables;
  117. select count(*) from t1;
  118. drop table t1;
  119.  
  120. #
  121. # Test rollback
  122. #
  123.  
  124. create table t1 (n int not null primary key) type=bdb;
  125. set autocommit=0;
  126. insert into t1 values (4);
  127. rollback;
  128. select n, "after rollback" from t1;
  129. insert into t1 values (4);
  130. commit;
  131. select n, "after commit" from t1;
  132. commit;
  133. insert into t1 values (5);
  134. -- error 1062
  135. insert into t1 values (4);
  136. commit;
  137. select n, "after commit" from t1;
  138. set autocommit=1;
  139. insert into t1 values (6);
  140. -- error 1062
  141. insert into t1 values (4);
  142. select n from t1;
  143. # nop
  144. rollback;
  145. drop table t1;
  146.  
  147. #
  148. # Testing transactions
  149. #
  150.  
  151. create table t1 ( id int NOT NULL PRIMARY KEY, nom varchar(64)) type=BDB;
  152. begin;
  153. insert into t1 values(1,'hamdouni');
  154. select id as afterbegin_id,nom as afterbegin_nom from t1;
  155. rollback;
  156. select id as afterrollback_id,nom as afterrollback_nom from t1;
  157. set autocommit=0;
  158. insert into t1 values(2,'mysql');
  159. select id as afterautocommit0_id,nom as afterautocommit0_nom from t1;
  160. rollback;
  161. select id as afterrollback_id,nom as afterrollback_nom from t1;
  162. set autocommit=1;
  163. drop table t1;
  164.  
  165. #
  166. # Simple not autocommit test
  167.  
  168. CREATE TABLE t1 (id char(8) not null primary key, val int not null) type=bdb;
  169. insert into t1 values ('pippo', 12);
  170. -- error 1062
  171. insert into t1 values ('pippo', 12); # Gives error
  172. delete from t1;
  173. delete from t1 where id = 'pippo';
  174. select * from t1;
  175.  
  176. insert into t1 values ('pippo', 12);
  177. set autocommit=0;
  178. delete from t1;
  179. rollback;
  180. select * from t1;
  181. delete from t1;
  182. commit;
  183. select * from t1;
  184. drop table t1;
  185. set autocommit=1;
  186.  
  187. #
  188. # The following simple tests failed at some point
  189. #
  190.  
  191. CREATE TABLE t1 (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR(64)) TYPE=BDB;
  192. INSERT INTO t1 VALUES (1, 'Jochen');
  193. select * from t1;
  194. drop table t1;
  195.  
  196. CREATE TABLE t1 ( _userid VARCHAR(60) NOT NULL PRIMARY KEY) TYPE=BDB;
  197. set autocommit=0;
  198. INSERT INTO t1  SET _userid='marc@anyware.co.uk';
  199. COMMIT;
  200. SELECT * FROM t1;
  201. SELECT _userid FROM t1 WHERE _userid='marc@anyware.co.uk';
  202. drop table t1;
  203. set autocommit=1;
  204.  
  205. #
  206. # Test when reading on part of unique key
  207. #
  208. CREATE TABLE t1 (
  209.   user_id int(10) DEFAULT '0' NOT NULL,
  210.   name varchar(100),
  211.   phone varchar(100),
  212.   ref_email varchar(100) DEFAULT '' NOT NULL,
  213.   detail varchar(200),
  214.   PRIMARY KEY (user_id,ref_email)
  215. )type=bdb;
  216.  
  217. INSERT INTO t1 VALUES (10292,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10292,'shirish','2333604','shirish@yahoo.com','ddsds'),(10292,'sonali','323232','sonali@bolly.com','filmstar');
  218. select * from t1 where user_id=10292;
  219. INSERT INTO t1 VALUES (10291,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10293,'shirish','2333604','shirish@yahoo.com','ddsds');
  220. select * from t1 where user_id=10292;
  221. select * from t1 where user_id>=10292;
  222. select * from t1 where user_id>10292;
  223. select * from t1 where user_id<10292;
  224. drop table t1;
  225.  
  226. #
  227. # Test that keys are created in right order
  228. #
  229.  
  230. CREATE TABLE t1 (a int not null, b int not null,c int not null,
  231. key(a),primary key(a,b), unique(c),key(a),unique(b));
  232. show index from t1;
  233. drop table t1;
  234.  
  235. #
  236. # Test of ALTER TABLE and BDB tables
  237. #
  238.  
  239. create table t1 (col1 int not null, col2 char(4) not null, primary key(col1));
  240. alter table t1 type=BDB;
  241. insert into t1 values ('1','1'),('5','2'),('2','3'),('3','4'),('4','4');
  242. select * from t1;
  243. update t1 set col2='7' where col1='4';
  244. select * from t1;
  245. alter table t1 add co3 int not null;
  246. select * from t1;
  247. update t1 set col2='9' where col1='2';
  248. select * from t1;
  249. drop table t1;
  250.  
  251. #
  252. # INSERT INTO BDB tables
  253. #
  254.  
  255. create table t1 (a int not null , b int, primary key (a)) type = BDB;
  256. create table t2 (a int not null , b int, primary key (a)) type = myisam;
  257. insert into t1 VALUES (1,3) , (2,3), (3,3);
  258. select * from t1;
  259. insert into t2 select * from t1;
  260. select * from t2;
  261. delete from t1 where b = 3;
  262. select * from t1;
  263. insert into t1 select * from t2;
  264. select * from t1;
  265. select * from t2;
  266. drop table t1,t2;
  267.  
  268. #
  269. # Search on unique key
  270. #
  271.  
  272. CREATE TABLE t1 (
  273.   id int(11) NOT NULL auto_increment,
  274.   ggid varchar(32) binary DEFAULT '' NOT NULL,
  275.   email varchar(64) DEFAULT '' NOT NULL,
  276.   passwd varchar(32) binary DEFAULT '' NOT NULL,
  277.   PRIMARY KEY (id),
  278.   UNIQUE ggid (ggid)
  279. ) TYPE=BDB;
  280.  
  281. insert into t1 (ggid,passwd) values ('test1','xxx');
  282. insert into t1 (ggid,passwd) values ('test2','yyy');
  283. -- error 1062
  284. insert into t1 (ggid,passwd) values ('test2','this will fail');
  285. -- error 1062
  286. insert into t1 (ggid,id) values ('this will fail',1);
  287.  
  288. select * from t1 where ggid='test1';
  289. select * from t1 where passwd='xxx';
  290. select * from t1 where id=2;
  291.  
  292. replace into t1 (ggid,id) values ('this will work',1);
  293. replace into t1 (ggid,passwd) values ('test2','this will work');
  294. -- error 1062
  295. update t1 set id=100,ggid='test2' where id=1;
  296. select * from t1;
  297. select * from t1 where id=1;
  298. select * from t1 where id=999;
  299. drop table t1;
  300.  
  301. #
  302. # ORDER BY on not primary key
  303. #
  304.  
  305. CREATE TABLE t1 (
  306.   user_name varchar(12),
  307.   password text,
  308.   subscribed char(1),
  309.   user_id int(11) DEFAULT '0' NOT NULL,
  310.   quota bigint(20),
  311.   weight double,
  312.   access_date date,
  313.   access_time time,
  314.   approved datetime,
  315.   dummy_primary_key int(11) NOT NULL auto_increment,
  316.   PRIMARY KEY (dummy_primary_key)
  317. ) TYPE=BDB;
  318. INSERT INTO t1 VALUES ('user_0','somepassword','N',0,0,0,'2000-09-07','23:06:59','2000-09-07 23:06:59',1);
  319. INSERT INTO t1 VALUES ('user_1','somepassword','Y',1,1,1,'2000-09-07','23:06:59','2000-09-07 23:06:59',2);
  320. INSERT INTO t1 VALUES ('user_2','somepassword','N',2,2,1.4142135623731,'2000-09-07','23:06:59','2000-09-07 23:06:59',3);
  321. INSERT INTO t1 VALUES ('user_3','somepassword','Y',3,3,1.7320508075689,'2000-09-07','23:06:59','2000-09-07 23:06:59',4);
  322. INSERT INTO t1 VALUES ('user_4','somepassword','N',4,4,2,'2000-09-07','23:06:59','2000-09-07 23:06:59',5);
  323. select  user_name, password , subscribed, user_id, quota, weight, access_date, access_time, approved, dummy_primary_key from t1 order by user_name;
  324. drop table t1;
  325.  
  326. #
  327. # Testing of tables without primary keys
  328. #
  329.  
  330. CREATE TABLE t1 (
  331.   id int(11) NOT NULL auto_increment,
  332.   parent_id int(11) DEFAULT '0' NOT NULL,
  333.   level tinyint(4) DEFAULT '0' NOT NULL,
  334.   KEY (id),
  335.   KEY parent_id (parent_id),
  336.   KEY level (level)
  337. ) type=bdb;
  338. INSERT INTO t1 VALUES (1,0,0),(3,1,1),(4,1,1),(8,2,2),(9,2,2),(17,3,2),(22,4,2),(24,4,2),(28,5,2),(29,5,2),(30,5,2),(31,6,2),(32,6,2),(33,6,2),(203,7,2),(202,7,2),(20,3,2),(157,0,0),(193,5,2),(40,7,2),(2,1,1),(15,2,2),(6,1,1),(34,6,2),(35,6,2),(16,3,2),(7,1,1),(36,7,2),(18,3,2),(26,5,2),(27,5,2),(183,4,2),(38,7,2),(25,5,2),(37,7,2),(21,4,2),(19,3,2),(5,1,1);
  339. INSERT INTO t1 values (179,5,2);
  340. update t1 set parent_id=parent_id+100;
  341. select * from t1 where parent_id=102;
  342. update t1 set id=id+1000;
  343. update t1 set id=1024 where id=1009; 
  344. select * from t1;
  345. update ignore t1 set id=id+1; # This will change all rows
  346. select * from t1;
  347. update ignore t1 set id=1023 where id=1010;
  348. select * from t1 where parent_id=102;
  349. explain select level from t1 where level=1;
  350. select level,id from t1 where level=1;
  351. select level,id,parent_id from t1 where level=1;
  352. select level,id from t1 where level=1 order by id;
  353. delete from t1 where level=1;
  354. select * from t1;
  355. drop table t1;
  356.  
  357. #
  358. # Test of index only reads
  359. #
  360. CREATE TABLE t1 (
  361.    sca_code char(6) NOT NULL,
  362.    cat_code char(6) NOT NULL,
  363.    sca_desc varchar(50),
  364.    lan_code char(2) NOT NULL,
  365.    sca_pic varchar(100),
  366.    sca_sdesc varchar(50),
  367.    sca_sch_desc varchar(16),
  368.    PRIMARY KEY (sca_code, cat_code, lan_code),
  369.    INDEX sca_pic (sca_pic)
  370. ) type = bdb ;
  371.  
  372. INSERT INTO t1 ( sca_code, cat_code, sca_desc, lan_code, sca_pic, sca_sdesc, sca_sch_desc) VALUES ( 'PD', 'J', 'PENDANT', 'EN', NULL, NULL, 'PENDANT'),( 'RI', 'J', 'RING', 'EN', NULL, NULL, 'RING'),( 'QQ', 'N', 'RING', 'EN', 'not null', NULL, 'RING');
  373. select count(*) from t1 where sca_code = 'PD';
  374. select count(*) from t1 where sca_code <= 'PD';
  375. select count(*) from t1 where sca_pic is null;
  376. alter table t1 drop index sca_pic, add index sca_pic (cat_code, sca_pic);
  377. select count(*) from t1 where sca_code='PD' and sca_pic is null;
  378. select count(*) from t1 where cat_code='E';
  379.  
  380. alter table t1 drop index sca_pic, add index (sca_pic, cat_code);
  381. select count(*) from t1 where sca_code='PD' and sca_pic is null;
  382. select count(*) from t1 where sca_pic >= 'n';
  383. select sca_pic from t1 where sca_pic is null;
  384. update t1 set sca_pic="test" where sca_pic is null;
  385. delete from t1 where sca_code='pd';
  386. drop table t1;
  387.  
  388. #
  389. # Test of opening table twice and timestamps
  390. #
  391. set @a:=now();
  392. CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) type=bdb;
  393. insert into t1 (a) values(1),(2),(3);
  394. select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a;
  395. update t1 set a=5 where a=1;
  396. select a from t1;
  397. drop table t1;
  398.  
  399. #
  400. # Test flushing of berkeley DB logs
  401. #
  402. flush logs;
  403.  
  404. #
  405. # Test key on blob with null values
  406. #
  407. create table t1 (b blob, i int, key (b(100)), key (i), key (i, b(20))) type=bdb;
  408. insert into t1 values ('this is a blob', 1), (null, -1), (null, null),("",1),("",2),("",3);
  409. select b from t1 where b = 'this is a blob';
  410. select * from t1 where b like 't%';
  411. select b, i from t1 where b is not null;
  412. select * from t1 where b is null and i > 0;
  413. select * from t1 where i is NULL;
  414. update t1 set b='updated' where i=1;
  415. select * from t1;
  416. drop table t1;
  417.  
  418. #
  419. # Test with variable length primary key
  420. #
  421. create table t1 (a varchar(100) not null, primary key(a), b int not null) type=bdb;
  422. insert into t1 values("hello",1),("world",2);
  423. select * from t1 order by b desc;
  424. optimize table t1;
  425. show keys from t1;
  426. drop table t1;
  427.  
  428. #
  429. # Test of bug in create index with NULL columns
  430. #
  431. create table t1 (i int, j int )TYPE=BDB;
  432. insert into t1 values (1,2);
  433. select * from t1 where i=1 and j=2;
  434. create index ax1 on t1 (i,j);
  435. select * from t1 where i=1 and j=2;
  436. drop table t1;
  437.  
  438. #
  439. # Test of with CONST tables and TEXT columns
  440. # This gave a wrong result because the row information was freed too early
  441. #
  442.  
  443. drop table if exists t1, t2, t3, t4, t5, t6, t7;
  444. create table t1
  445. (
  446.     branch_id    int        auto_increment    primary key,
  447.     branch_name    varchar(255)    not null,
  448.     branch_active    int        not null     default 1,
  449.  
  450.     unique  branch_name(branch_name),
  451.     index    branch_active(branch_active)
  452. ) type=bdb;
  453. drop table if exists t2 ;
  454. create table t2
  455. (
  456.     target_id    int        auto_increment    primary key,
  457.     target_name    varchar(255)    not null,
  458.     target_active    int        not null     default 1,
  459.  
  460.     unique    target_name(target_name),
  461.     index    target_active(target_active)
  462. ) type=bdb;
  463. drop table if exists t3 ;
  464. create table t3
  465. (
  466.     platform_id    int        auto_increment    primary key,
  467.     platform_name    varchar(255)    not null,
  468.     platform_active    int        not null     default 1,
  469.  
  470.     unique    platform_name(platform_name),
  471.     index    platform_active(platform_active)
  472. ) type=bdb;
  473. drop table if exists t4 ;
  474. create table t4
  475. (
  476.     product_id    int        auto_increment    primary key,
  477.     product_name    varchar(255)    not null,
  478.     version_file    varchar(255)    not null,
  479.     product_active    int        not null     default 1,
  480.  
  481.     unique    product_name(product_name),
  482.     index    product_active(product_active)
  483. ) type=bdb;
  484. drop table if exists t5 ;
  485. create table t5
  486. (
  487.     product_file_id        int        auto_increment    primary key,
  488.     product_id        int        not null,
  489.     file_name        varchar(255)    not null,
  490.     /* cvs module used to find the file version */
  491.     module_name        varchar(255)    not null,
  492.     /* flag whether the file is still included in the product */
  493.     file_included        int        not null    default 1,
  494.  
  495.     unique    product_file(product_id,file_name),
  496.     index    file_included(file_included)
  497. ) type=bdb;
  498. drop table if exists t6 ;
  499. create table t6
  500. (
  501.     file_platform_id    int        auto_increment    primary key,
  502.     product_file_id        int        not null,
  503.     platform_id        int        not null,
  504.     branch_id        int        not null,
  505.     /* filename in the build system */
  506.     build_filename        varchar(255)    not null,
  507.     /* default filename in the build archive */
  508.     archive_filename    varchar(255)    not null,
  509.  
  510.     unique  file_platform(product_file_id,platform_id,branch_id)
  511. ) type=bdb;
  512. drop table if exists t8 ;
  513. create table t8
  514. (
  515.     archive_id    int        auto_increment    primary key,
  516.     branch_id    int        not null,
  517.     target_id    int        not null,
  518.     platform_id    int        not null,
  519.     product_id    int        not null,
  520.     status_id    int        not null    default 1,
  521.  
  522.     unique  archive(branch_id,target_id,platform_id,product_id),
  523.     index    status_id(status_id)
  524. ) type=bdb;
  525. drop table if exists t7 ;
  526. create table t7
  527. (
  528.     build_id    int        auto_increment    primary key,
  529.     branch_id    int        not null,
  530.     target_id    int        not null,
  531.     build_number    int        not null,
  532.     build_date    date        not null,
  533.     /* build system tag, e.g. 'rmanight-022301-1779' */
  534.     build_tag    varchar(255)    not null,    
  535.     /* path relative to the build archive root, e.g. 'current' */
  536.     build_path    text        not null,    
  537.  
  538.     unique  build(branch_id,target_id,build_number)
  539. ) type=bdb;
  540.  
  541. insert into t1 (branch_name)
  542. values ('RealMedia');
  543. insert into t1 (branch_name)
  544. values ('RP8REV');
  545. insert into t1 (branch_name)
  546. values ('SERVER_8_0_GOLD');
  547.  
  548. insert into t2 (target_name)
  549. values ('rmanight');
  550. insert into t2 (target_name)
  551. values ('playerall');
  552. insert into t2 (target_name)
  553. values ('servproxyall');
  554.  
  555. insert into t3 (platform_name)
  556. values ('linux-2.0-libc6-i386');
  557. insert into t3 (platform_name)
  558. values ('win32-i386');
  559.  
  560. insert into t4 (product_name, version_file)
  561. values ('realserver', 'servinst');
  562. insert into t4 (product_name, version_file)
  563. values ('realproxy', 'prxyinst');
  564. insert into t4 (product_name, version_file)
  565. values ('realplayer', 'playinst');
  566. insert into t4 (product_name, version_file)
  567. values ('plusplayer', 'plusinst');
  568.  
  569. create temporary table tmp1
  570.         select branch_id, target_id, platform_id, product_id
  571.         from t1, t2, t3, t4 ;
  572. create temporary table tmp2 
  573.         select tmp1.branch_id, tmp1.target_id, tmp1.platform_id, tmp1.product_id 
  574.         from tmp1 left join t8 
  575.         using (branch_id,target_id,platform_id,product_id) 
  576.         where t8.archive_id is null ;
  577. insert into t8 
  578.         (branch_id, target_id, platform_id, product_id, status_id)
  579.         select branch_id, target_id, platform_id, product_id, 1
  580.         from tmp2 ;
  581. drop table tmp1 ;
  582. drop table tmp2 ;
  583.  
  584. insert into t5 (product_id, file_name, module_name)
  585. values (1, 'servinst', 'server');
  586.  
  587. insert into t5 (product_id, file_name, module_name)
  588. values (2, 'prxyinst', 'server');
  589.  
  590. insert into t5 (product_id, file_name, module_name)
  591. values (3, 'playinst', 'rpapp');
  592.  
  593. insert into t5 (product_id, file_name, module_name)
  594. values (4, 'plusinst', 'rpapp');
  595.  
  596. insert into t6 
  597. (product_file_id,platform_id,branch_id,build_filename,archive_filename)
  598. values (1, 2, 3, 'servinst.exe', 'win32-servinst.exe');
  599.  
  600. insert into t6 
  601. (product_file_id,platform_id,branch_id,build_filename,archive_filename)
  602. values (1, 1, 3, 'v80_linux-2.0-libc6-i386_servinst.bin', 'linux2-servinst.exe');
  603.  
  604. insert into t6 
  605. (product_file_id,platform_id,branch_id,build_filename,archive_filename)
  606. values (3, 2, 2, 'playinst.exe', 'win32-playinst.exe');
  607.  
  608. insert into t6 
  609. (product_file_id,platform_id,branch_id,build_filename,archive_filename)
  610. values (4, 2, 2, 'playinst.exe', 'win32-playinst.exe');
  611.  
  612. insert into t7 
  613. (branch_id,target_id,build_number,build_tag,build_date,build_path)
  614. values (2, 2, 1071, 'playerall-022101-1071', '2001-02-21', 'current');
  615.  
  616. insert into t7 
  617. (branch_id,target_id,build_number,build_tag,build_date,build_path)
  618. values (2, 2, 1072, 'playerall-022201-1072', '2001-02-22', 'current');
  619.  
  620. insert into t7 
  621. (branch_id,target_id,build_number,build_tag,build_date,build_path)
  622. values (3, 3, 388, 'servproxyall-022201-388', '2001-02-22', 'current');
  623.  
  624. insert into t7 
  625. (branch_id,target_id,build_number,build_tag,build_date,build_path)
  626. values (3, 3, 389, 'servproxyall-022301-389', '2001-02-23', 'current');
  627.  
  628. insert into t7 
  629. (branch_id,target_id,build_number,build_tag,build_date,build_path)
  630. values (4, 4, 100, 'foo target-010101-100', '2001-01-01', 'current');
  631.  
  632. update t8
  633. set status_id=2
  634. where branch_id=2 and target_id=2 and platform_id=2 and product_id=1;
  635.  
  636. select t7.build_path
  637. from 
  638.     t1, 
  639.     t7, 
  640.     t2, 
  641.     t3, 
  642.     t4,
  643.     t5, 
  644.     t6
  645. where 
  646.     t7.branch_id = t1.branch_id and 
  647.     t7.target_id = t2.target_id and 
  648.     t5.product_id = t4.product_id and
  649.     t6.product_file_id = t5.product_file_id and
  650.     t6.platform_id = t3.platform_id and
  651.     t6.branch_id = t6.branch_id and
  652.     t7.build_id = 1 and
  653.     t4.product_id = 3 and
  654.     t5.file_name = 'playinst' and
  655.     t3.platform_id = 2;
  656.  
  657. drop table t1, t2, t3, t4, t5, t6, t7, t8;
  658.  
  659. #
  660. # Test with blob + tinyint key
  661. #
  662.  
  663. CREATE TABLE t1 (
  664.   a tinytext NOT NULL,
  665.   b tinyint(3) unsigned NOT NULL default '0',
  666.   PRIMARY KEY (a(32),b)
  667. ) TYPE=BDB;
  668. INSERT INTO t1 VALUES ('a',1),('a',2);
  669. SELECT * FROM t1 WHERE a='a' AND b=2;
  670. SELECT * FROM t1 WHERE a='a' AND b in (2);
  671. SELECT * FROM t1 WHERE a='a' AND b in (1,2);
  672. drop table t1;
  673.  
  674. #
  675. # Test min-max optimization
  676. #
  677.  
  678. CREATE TABLE t1 (
  679.   a int3 unsigned NOT NULL,
  680.   b int1 unsigned NOT NULL,
  681.   UNIQUE (a, b)
  682. ) TYPE = BDB;
  683.  
  684. INSERT INTO t1 VALUES (1, 1);
  685. SELECT MIN(B),MAX(b) FROM t1 WHERE t1.a = 1;
  686. drop table t1;
  687.  
  688. #
  689. # Test problem with BDB and lock tables with duplicate write.
  690. #
  691.  
  692. create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) type=bdb;
  693. insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
  694. LOCK TABLES t1 WRITE;
  695. --error 1062
  696. insert into t1 values (99,1,2,'D'),(1,1,2,'D');
  697. select id from t1;
  698. select id from t1;
  699. UNLOCK TABLES;
  700. DROP TABLE t1;
  701.  
  702. create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) type=bdb;
  703. insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
  704. LOCK TABLES t1 WRITE;
  705. begin;
  706. --error 1062
  707. insert into t1 values (99,1,2,'D'),(1,1,2,'D');
  708. select id from t1;
  709. insert ignore into t1 values (100,1,2,'D'),(1,1,99,'D');
  710. commit;
  711. select id,id3 from t1;
  712. UNLOCK TABLES;
  713. DROP TABLE t1;
  714.  
  715. #
  716. # Test with empty tables (crashed with lock error)
  717. #
  718.  
  719. CREATE TABLE t1 (SYAIN_NO char(5) NOT NULL default '', KINMU_DATE char(6) NOT NULL default '', PRIMARY KEY  (SYAIN_NO,KINMU_DATE)) TYPE=BerkeleyDB;
  720. CREATE TABLE t2 ( SYAIN_NO char(5) NOT NULL default '',STR_DATE char(8) NOT NULL default '',PRIMARY KEY  (SYAIN_NO,STR_DATE) ) TYPE=BerkeleyDB;
  721. select T1.KINMU_DATE from t1 T1 ,t2 T2 where  T1.SYAIN_NO = '12345' and T1.KINMU_DATE = '200106' and T2.SYAIN_NO = T1.SYAIN_NO;
  722. select T1.KINMU_DATE from t1 T1 ,t2 T2 where  T1.SYAIN_NO = '12345' and T1.KINMU_DATE = '200106' and T2.SYAIN_NO = T1.SYAIN_NO;
  723. DROP TABLE t1,t2;
  724.  
  725. #
  726. # Test problem with joining table to itself on a multi-part unique key
  727. #
  728.  
  729. drop table if exists t1;
  730. create table t1 (a int(11) not null, b int(11) not null, unique (a,b)) type=bdb;
  731. insert into t1 values (1,1), (1,2);
  732. select * from t1 where a = 1;
  733. select t1.*, t2.* from t1, t1 t2 where t1.a = t2.a and t2.a = 1;
  734. select * from t1 where a = 1;
  735. drop table t1;
  736.  
  737. #
  738. # This caused a deadlock in BDB internal locks
  739. #
  740.  
  741. create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) type=bdb;
  742. insert into t1 values (0,0,0,'ABCDEFGHIJ');
  743. create table t2 (id int NOT NULL,primary key (id)) type=bdb;
  744. LOCK TABLES t1 WRITE, t2 WRITE;
  745. insert into t2 values(1);
  746. SELECT t1.* FROM t1 WHERE id IN (1);
  747. SELECT t1.* FROM t2 left outer join t1 on (t1.id=t2.id);
  748. delete from t1 where id3 >= 0 and id3 <= 0;
  749. drop table t1,t2;
  750.  
  751. #
  752. # Test problems with NULL
  753. #
  754.  
  755. CREATE TABLE t1 (i varchar(48) NOT NULL default '', p varchar(255) default NULL,s varchar(48) NOT NULL default '', PRIMARY KEY  (i), UNIQUE(p,s)) TYPE=BDB;
  756. INSERT INTO t1 VALUES ('00000000-e6c4ddeaa6-003b8-83458387','programs/xxxxxxxx.wmv','00000000-e6c4ddeb32-003bc-83458387');
  757. SELECT * FROM t1 WHERE p='programs/xxxxxxxx.wmv';
  758. drop table t1;
  759.  
  760. #
  761. # Test problem which gave error 'Can't find record in 't1''
  762. #
  763.  
  764. CREATE TABLE t1 ( STR_DATE varchar(8) NOT NULL default '',INFO_NOTE varchar(200) default NULL,PRIMARY KEY  (STR_DATE) ) TYPE=BerkeleyDB;
  765. select INFO_NOTE from t1 where STR_DATE = '20010610';
  766. select INFO_NOTE from t1 where STR_DATE < '20010610';
  767. select INFO_NOTE from t1 where STR_DATE > '20010610';
  768. drop table t1;
  769.