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 / gemini.test < prev    next >
Encoding:
Text File  |  2003-01-21  |  10.6 KB  |  356 lines  |  [TEXT/ttxt]

  1. -- source include/have_gemini.inc
  2.  
  3. #
  4. # Small basic test with ignore
  5. #
  6.  
  7. drop table if exists t1;
  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=gemini;
  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=gemini;
  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. !$1062 update t1 set id=1024 where id=1009; 
  37. select * from t1;
  38. update ignore t1 set id=id+1; # This will change all rows
  39. select * from t1;
  40. update ignore t1 set id=1023 where id=1010;
  41. select * from t1 where parent_id=102;
  42. explain select level from t1 where level=1;
  43. explain select level,id from t1 where level=1;
  44. explain select level,id,parent_id from t1 where level=1;
  45. select level,id from t1 where level=1;
  46. select level,id,parent_id from t1 where level=1;
  47. drop table t1;
  48.  
  49. #
  50. # Test replace
  51. #
  52.  
  53. CREATE TABLE t1 (
  54.   gesuchnr int(11) DEFAULT '0' NOT NULL,
  55.   benutzer_id int(11) DEFAULT '0' NOT NULL,
  56.   PRIMARY KEY (gesuchnr,benutzer_id)
  57. ) type=gemini;
  58.  
  59. replace into t1 (gesuchnr,benutzer_id) values (2,1);
  60. replace into t1 (gesuchnr,benutzer_id) values (1,1);
  61. replace into t1 (gesuchnr,benutzer_id) values (1,1);
  62. select * from t1;
  63. drop table t1;
  64.  
  65. #
  66. # test delete using hidden_primary_key
  67. #
  68.  
  69. create table t1 (a int) type=gemini;
  70. insert into t1 values (1), (2);
  71. delete from t1 where a = 1;
  72. select * from t1;
  73. drop table t1;
  74.  
  75. #
  76. # Test auto_increment on sub key
  77. #
  78.  
  79. #create table t1 (a char(10) not null, b int not null auto_increment, primary key(a,b)) type=gemini;
  80. #insert into t1 values ("a",1),("b",2),("a",2),("c",1);
  81. #insert into t1 values ("a",NULL),("b",NULL),("c",NULL),("e",NULL);
  82. #insert into t1 (a) values ("a"),("b"),("c"),("d");
  83. #insert into t1 (a) values ('k'),('d');
  84. #insert into t1 (a) values ("a");
  85. #insert into t1 values ("d",last_insert_id());
  86. #select * from t1;
  87. #drop table t1;
  88.  
  89. #
  90. # Test when reading on part of unique key
  91. #
  92. CREATE TABLE t1 (
  93.   user_id int(10) DEFAULT '0' NOT NULL,
  94.   name varchar(100),
  95.   phone varchar(100),
  96.   ref_email varchar(100) DEFAULT '' NOT NULL,
  97.   detail varchar(200),
  98.   PRIMARY KEY (user_id,ref_email)
  99. )type=gemini;
  100.  
  101. 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');
  102. select * from t1 where user_id=10292;
  103. INSERT INTO t1 VALUES (10291,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10293,'shirish','2333604','shirish@yahoo.com','ddsds');
  104. select * from t1 where user_id=10292;
  105. select * from t1 where user_id>=10292;
  106. select * from t1 where user_id>10292;
  107. select * from t1 where user_id<10292;
  108. drop table t1;
  109.  
  110. #
  111. # Test that keys are created in right order
  112. #  - Needs ANALYZE TABLE to work - MikeF 2/12/01
  113. #
  114. #CREATE TABLE t1 (a int not null, b int not null,c int not null,
  115. #key(a),primary key(a,b), unique(c),key(a),unique(b)) type = gemini;
  116. #show index from t1;
  117. #drop table t1;
  118.  
  119. #
  120. # Test of ALTER TABLE and gemini tables
  121. #
  122.  
  123. #create table t1 (col1 int not null, col2 char(4) not null, primary key(col1));
  124. #alter table t1 type=gemini;
  125. #insert into t1 values ('1','1'),('5','2'),('2','3'),('3','4'),('4','4');
  126. #select * from t1;
  127. #update t1 set col2='7' where col1='4';
  128. #select * from t1;
  129. #alter table t1 add co3 int not null;
  130. #select * from t1;
  131. #update t1 set col2='9' where col1='2';
  132. #select * from t1;
  133. #drop table t1;
  134.  
  135. #
  136. # INSERT INTO gemini tables
  137. #
  138.  
  139. create table t1 (a int not null , b int, primary key (a)) type = gemini;
  140. create table t2 (a int not null , b int, primary key (a)) type = myisam;
  141. insert into t1 VALUES (1,3) , (2,3), (3,3);
  142. select * from t1;
  143. insert into t2 select * from t1;
  144. select * from t2;
  145. delete from t1 where b = 3;
  146. select * from t1;
  147. insert into t1 select * from t2;
  148. select * from t1;
  149. select * from t2;
  150. drop table t1,t2;
  151.  
  152. #
  153. # Search on unique key
  154. #
  155.  
  156. CREATE TABLE t1 (
  157.   id int(11) NOT NULL auto_increment,
  158.   ggid varchar(32) binary DEFAULT '' NOT NULL,
  159.   email varchar(64) DEFAULT '' NOT NULL,
  160.   passwd varchar(32) binary DEFAULT '' NOT NULL,
  161.   PRIMARY KEY (id),
  162.   UNIQUE ggid (ggid)
  163. ) TYPE=gemini;
  164.  
  165. insert into t1 (ggid,passwd) values ('test1','xxx');
  166. insert into t1 (ggid,passwd) values ('test2','yyy');
  167.  
  168. select * from t1 where ggid='test1';
  169. select * from t1 where passwd='xxx';
  170. select * from t1 where id=2;
  171. drop table t1;
  172.  
  173. #
  174. # ORDER BY on not primary key
  175. #
  176.  
  177. #CREATE TABLE t1 (
  178. #  user_name varchar(12),
  179.   #password text,
  180.   #subscribed char(1),
  181.   #user_id int(11) DEFAULT '0' NOT NULL,
  182.   #quota bigint(20),
  183.   #weight double,
  184.   #access_date date,
  185.   #access_time time,
  186.   #approved datetime,
  187.   #dummy_primary_key int(11) NOT NULL auto_increment,
  188.   #PRIMARY KEY (dummy_primary_key)
  189. #) TYPE=gemini;
  190. #INSERT INTO t1 VALUES ('user_0','somepassword','N',0,0,0,'2000-09-07','23:06:59','2000-09-07 23:06:59',1);
  191. #INSERT INTO t1 VALUES ('user_1','somepassword','Y',1,1,1,'2000-09-07','23:06:59','2000-09-07 23:06:59',2);
  192. #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);
  193. #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);
  194. #INSERT INTO t1 VALUES ('user_4','somepassword','N',4,4,2,'2000-09-07','23:06:59','2000-09-07 23:06:59',5);
  195. #select  user_name, password , subscribed, user_id, quota, weight, access_date, access_time, approved, dummy_primary_key from t1 order by user_name;
  196. #drop table t1;
  197.  
  198. #
  199. # Testing of tables without primary keys
  200. #
  201.  
  202. CREATE TABLE t1 (
  203.   id int(11) NOT NULL auto_increment,
  204.   parent_id int(11) DEFAULT '0' NOT NULL,
  205.   level tinyint(4) DEFAULT '0' NOT NULL,
  206.   KEY (id),
  207.   KEY parent_id (parent_id),
  208.   KEY level (level)
  209. ) type=gemini;
  210. 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);
  211. INSERT INTO t1 values (179,5,2);
  212. update t1 set parent_id=parent_id+100;
  213. select * from t1 where parent_id=102;
  214. update t1 set id=id+1000;
  215. update t1 set id=1024 where id=1009; 
  216. select * from t1;
  217. update ignore t1 set id=id+1; # This will change all rows
  218. select * from t1;
  219. update ignore t1 set id=1023 where id=1010;
  220. select * from t1 where parent_id=102;
  221. explain select level from t1 where level=1;
  222. select level,id from t1 where level=1;
  223. select level,id,parent_id from t1 where level=1;
  224. select level,id from t1 where level=1 order by id;
  225. delete from t1 where level=1;
  226. select * from t1;
  227. drop table t1;
  228.  
  229. #
  230. # Test of index only reads
  231. #
  232. CREATE TABLE t1 (
  233.    sca_code char(6) NOT NULL,
  234.    cat_code char(6) NOT NULL,
  235.    sca_desc varchar(50),
  236.    lan_code char(2) NOT NULL,
  237.    sca_pic varchar(100),
  238.    sca_sdesc varchar(50),
  239.    sca_sch_desc varchar(16),
  240.    PRIMARY KEY (sca_code, cat_code, lan_code)
  241. ) type = gemini ;
  242.  
  243. 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');
  244. select count(*) from t1 where sca_code = 'PD';
  245. drop table t1;
  246.  
  247. #
  248. # Test of opening table twice
  249. #
  250. CREATE TABLE t1 (a int not null, primary key (a)) type=gemini;
  251. insert into t1 values(1),(2),(3);
  252. select t1.a from t1 natural join t1 as t2 order by t1.a;
  253. drop table t1;
  254.  
  255. #
  256. # Test rollback
  257. #
  258.  
  259. select "test for rollback";
  260. create table t1 (n int not null primary key) type=gemini;
  261. set autocommit=0;
  262. insert into t1 values (4);
  263. commit;
  264. insert into t1 values (5);
  265. rollback;
  266. select n, "after rollback" from t1;
  267. insert into t1 values (5);
  268. commit;
  269. select n, "after commit" from t1;
  270. commit;
  271. insert into t1 values (6);
  272. !$1062 insert into t1 values (4);
  273. commit;
  274. select n, "after commit" from t1;
  275. set autocommit=1;
  276. insert into t1 values (7);
  277. !$1062 insert into t1 values (4);
  278. select n from t1;
  279. # nop
  280. rollback;
  281. drop table t1;
  282.  
  283. #
  284. # Testing transactions
  285. #
  286.  
  287. create table t1 ( id int NOT NULL PRIMARY KEY, nom varchar(64)) type=gemini;
  288. insert into t1 values(1,'first');
  289. begin;
  290. insert into t1 values(2,'hamdouni');
  291. select id as afterbegin_id,nom as afterbegin_nom from t1;
  292. rollback;
  293. select id as afterrollback_id,nom as afterrollback_nom from t1;
  294. set autocommit=0;
  295. insert into t1 values(3,'mysql');
  296. select id as afterautocommit0_id,nom as afterautocommit0_nom from t1;
  297. rollback;
  298. select id as afterrollback_id,nom as afterrollback_nom from t1;
  299. set autocommit=1;
  300. drop table t1;
  301.  
  302. #
  303. # Simple not autocommit test
  304.  
  305. CREATE TABLE t1 (id char(8) not null primary key, val int not null) type=gemini;
  306. insert into t1 values ('pippo', 12);
  307. !$1062 insert into t1 values ('pippo', 12); # Gives error
  308. delete from t1;
  309. delete from t1 where id = 'pippo';
  310. select * from t1;
  311.  
  312. insert into t1 values ('pippo', 12);
  313. set autocommit=0;
  314. delete from t1;
  315. rollback;
  316. select * from t1;
  317. delete from t1;
  318. commit;
  319. select * from t1;
  320. drop table t1;
  321. set autocommit=1;
  322.  
  323. #
  324. # The following simple tests failed at some point
  325. #
  326.  
  327. CREATE TABLE t1 (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR(64)) TYPE=gemini;
  328. INSERT INTO t1 VALUES (1, 'Jochen');
  329. select * from t1;
  330. drop table t1;
  331.  
  332. CREATE TABLE t1 ( _userid VARCHAR(60) NOT NULL PRIMARY KEY) TYPE=gemini;
  333. set autocommit=0;
  334. INSERT INTO t1  SET _userid='marc@anyware.co.uk';
  335. COMMIT;
  336. SELECT * FROM t1;
  337. SELECT _userid FROM t1 WHERE _userid='marc@anyware.co.uk';
  338. drop table t1;
  339. set autocommit=1;
  340.  
  341. #
  342. # Test of load data infile
  343. #
  344.  
  345. CREATE TABLE if not exists `t1` (
  346.   `f1` int(11) unsigned NOT NULL default '0',
  347.   `f2` tinyint(3) unsigned NOT NULL default '0',
  348.   `f3` tinyint(3) unsigned NOT NULL default '0',
  349.   PRIMARY KEY  (`f1`)
  350. ) TYPE=Gemini;
  351. lock table t1 write;
  352. load data infile ''../../std_data/gemini.dat' ignore into table t1 fields terminated by ',';
  353. select f1 from t1;
  354. drop table t1;
  355.