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

  1. #
  2. # Check null keys
  3.  
  4. drop table if exists t1;
  5. create table t1 (a int, b int not null,unique key (a,b),index(b)) type=myisam;
  6. insert ignore into t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(null,7),(9,9),(8,8),(7,7),(null,9),(null,9),(6,6);
  7. explain select * from t1 where a is null;
  8. explain select * from t1 where a is null and b = 2;
  9. explain select * from t1 where a is null and b = 7;
  10. explain select * from t1 where a=2 and b = 2;
  11. explain select * from t1 where a<=>b limit 2;
  12. explain select * from t1 where (a is null or a > 0 and a < 3) and b < 5 limit 3;
  13. explain select * from t1 where (a is null or a = 7) and b=7;
  14. explain select * from t1 where (a is null and b>a) or a is null and b=7 limit 2;
  15. explain select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
  16. explain select * from t1 where a > 1 and a < 3 limit 1;
  17. explain select * from t1 where a > 8 and a < 9;
  18. select * from t1 where a is null;
  19. select * from t1 where a is null and b = 7;
  20. select * from t1 where a<=>b limit 2;
  21. select * from t1 where (a is null or a > 0 and a < 3) and b < 5 limit 3;
  22. select * from t1 where (a is null or a > 0 and a < 3) and b > 7 limit 3;
  23. select * from t1 where (a is null or a = 7) and b=7;
  24. select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
  25. alter table t1 modify b blob not null, add c int not null, drop key a, add unique key (a,b(20),c), drop key b, add key (b(10));
  26. explain select * from t1 where a is null and b = 2;
  27. explain select * from t1 where a is null and b = 2 and c=0;
  28. explain select * from t1 where a is null and b = 7 and c=0;
  29. explain select * from t1 where a=2 and b = 2;
  30. explain select * from t1 where a<=>b limit 2;
  31. explain select * from t1 where (a is null or a > 0 and a < 3) and b < 5 and c=0 limit 3;
  32. explain select * from t1 where (a is null or a = 7) and b=7 and c=0;
  33. explain select * from t1 where (a is null and b>a) or a is null and b=7 limit 2;
  34. explain select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
  35. explain select * from t1 where a > 1 and a < 3 limit 1;
  36. explain select * from t1 where a is null and b=7 or a > 1 and a < 3 limit 1;
  37. explain select * from t1 where a > 8 and a < 9;
  38. explain select * from t1 where b like "6%";
  39. select * from t1 where a is null;
  40. select * from t1 where a is null and b = 7 and c=0;
  41. select * from t1 where a<=>b limit 2;
  42. select * from t1 where (a is null or a > 0 and a < 3) and b < 5 limit 3;
  43. select * from t1 where (a is null or a > 0 and a < 3) and b > 7 limit 3;
  44. select * from t1 where (a is null or a = 7) and b=7 and c=0;
  45. select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
  46. select * from t1 where b like "6%";
  47. drop table t1;
  48.  
  49.  
  50. #
  51. # The following failed for Matt Loschert
  52. #
  53.  
  54. DROP TABLE IF EXISTS t1,t2;
  55. CREATE TABLE t1 (
  56.   id int(10) unsigned NOT NULL auto_increment,
  57.   uniq_id int(10) unsigned default NULL,
  58.   PRIMARY KEY  (id),
  59.   UNIQUE KEY idx1 (uniq_id)
  60. ) TYPE=MyISAM;
  61.  
  62. CREATE TABLE t2 (
  63.   id int(10) unsigned NOT NULL auto_increment,
  64.   uniq_id int(10) unsigned default NULL,
  65.   PRIMARY KEY  (id)
  66. ) TYPE=MyISAM;
  67.  
  68. INSERT INTO t1 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL);
  69. INSERT INTO t2 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL);
  70.  
  71. #
  72. # Check IS NULL optimization
  73. #
  74. explain select id from t1 where uniq_id is null;
  75. explain select id from t1 where uniq_id =1;
  76. #
  77. # Check updates
  78. #
  79. UPDATE t1 SET id=id+100 where uniq_id is null;
  80. UPDATE t2 SET id=id+100 where uniq_id is null;
  81. select id from t1 where uniq_id is null;
  82. select id from t2 where uniq_id is null;
  83. #
  84. # Delete all records from each table where the uniq_id field is null
  85. #
  86. DELETE FROM t1 WHERE uniq_id IS NULL;
  87. DELETE FROM t2 WHERE uniq_id IS NULL;
  88. #
  89. # Select what is left -- notice the difference
  90. #
  91. SELECT * FROM t1 ORDER BY uniq_id, id;
  92. SELECT * FROM t2 ORDER BY uniq_id, id;
  93. DROP table t1,t2;
  94.  
  95. #
  96. # This crashed MySQL 3.23.47
  97. #
  98.  
  99. CREATE TABLE `t1` (
  100.   `order_id` char(32) NOT NULL default '',
  101.   `product_id` char(32) NOT NULL default '',
  102.   `product_type` int(11) NOT NULL default '0',
  103.   PRIMARY KEY  (`order_id`,`product_id`,`product_type`)
  104. ) TYPE=MyISAM;
  105. CREATE TABLE `t2` (
  106.   `order_id` char(32) NOT NULL default '',
  107.   `product_id` char(32) NOT NULL default '',
  108.   `product_type` int(11) NOT NULL default '0',
  109.   PRIMARY KEY  (`order_id`,`product_id`,`product_type`)
  110. ) TYPE=MyISAM;
  111. INSERT INTO t1 (order_id, product_id, product_type) VALUES
  112. ('3d7ce39b5d4b3e3d22aaafe9b633de51',1206029, 3),
  113. ('3d7ce39b5d4b3e3d22aaafe9b633de51',5880836, 3),
  114. ('9d9aad7764b5b2c53004348ef8d34500',2315652, 3);
  115. INSERT INTO t2 (order_id, product_id, product_type) VALUES
  116. ('9d9aad7764b5b2c53004348ef8d34500',2315652, 3);
  117.  
  118. select t1.* from t1
  119. left join t2 using(order_id, product_id, product_type)
  120. where t2.order_id=NULL;
  121. select t1.* from t1
  122. left join t2 using(order_id, product_id, product_type)
  123. where t2.order_id is NULL;
  124. drop table t1,t2;
  125.  
  126. #
  127. # The last select returned wrong results in 3.23.52
  128. #
  129.  
  130. create table t1 (id int);
  131. insert into t1 values (null), (0);
  132. create table t2 (id int);
  133. insert into t2 values (null);
  134. select * from t1, t2 where t1.id = t2.id;
  135. alter table t1 add key id (id);
  136. select * from t1, t2 where t1.id = t2.id;
  137. drop table t1,t2;
  138.  
  139. #
  140. # Check bug when doing <=> NULL on an indexed null field
  141. #
  142.  
  143. create table t1 (
  144.   id  integer,
  145.   id2 integer not null,
  146.   index (id),
  147.   index (id2)
  148. );
  149. insert into t1 values(null,null),(1,1);
  150. select * from t1;
  151. select * from t1 where id <=> null;
  152. select * from t1 where id <=> null or id > 0;
  153. select * from t1 where id is null or id > 0;
  154. select * from t1 where id2 <=> null or id2 > 0;
  155. select * from t1 where id2 is null or id2 > 0;
  156. delete from t1 where id <=> NULL;
  157. select * from t1;
  158. drop table t1;
  159.