merge.test
上传用户:tsgydb
上传日期:2007-04-14
资源大小:10674k
文件大小:3k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. #
  2. # test of MERGE TABLES
  3. #
  4. drop table if exists t1,t2,t3;
  5. create table t1 (a int not null primary key auto_increment, message char(20));
  6. create table t2 (a int not null primary key auto_increment, message char(20));
  7. INSERT INTO t1 (message) VALUES ("Testing"),("table"),("t1");
  8. INSERT INTO t2 (message) VALUES ("Testing"),("table"),("t2");
  9. create table t3 (a int not null, b char(20), key(a)) type=MERGE UNION=(t1,t2);
  10. select * from t3;
  11. select * from t3 order by a desc;
  12. drop table t3;
  13. insert into t1 select NULL,message from t2;
  14. insert into t2 select NULL,message from t1;
  15. insert into t1 select NULL,message from t2;
  16. insert into t2 select NULL,message from t1;
  17. insert into t1 select NULL,message from t2;
  18. insert into t2 select NULL,message from t1;
  19. insert into t1 select NULL,message from t2;
  20. insert into t2 select NULL,message from t1;
  21. insert into t1 select NULL,message from t2;
  22. insert into t2 select NULL,message from t1;
  23. insert into t1 select NULL,message from t2;
  24. create table t3 (a int not null, b char(20), key(a)) type=MERGE UNION=(t1,t2);
  25. explain select * from t3 where a < 10;
  26. explain select * from t3 where a > 10 and a < 20;
  27. select * from t3 where a = 10;
  28. select * from t3 where a < 10;
  29. select * from t3 where a > 10 and a < 20;
  30. explain select a from t3 order by a desc limit 10;
  31. select a from t3 order by a desc limit 10;
  32. select a from t3 order by a desc limit 300,10;
  33. show create table t3;
  34. # The following should give errors
  35. create table t4 (a int not null, b char(10), key(a)) type=MERGE UNION=(t1,t2);
  36. # Because of windows, it's important that we drop the merge tables first!
  37. drop table if exists t4,t3,t1,t2;
  38. create table t1 (c char(10)) type=myisam;
  39. create table t2 (c char(10)) type=myisam;
  40. create table t3 (c char(10)) union=(t1,t2) type=merge;
  41. insert into t1 (c) values ('test1');
  42. insert into t1 (c) values ('test1');
  43. insert into t1 (c) values ('test1');
  44. insert into t2 (c) values ('test2');
  45. insert into t2 (c) values ('test2');
  46. insert into t2 (c) values ('test2');
  47. select * from t3;
  48. select * from t3;
  49. delete from t3 where 1=1;
  50. select * from t3;
  51. select * from t1;
  52. drop table t3,t2,t1;
  53. #
  54. # Test 2
  55. #
  56. CREATE TABLE t1 (incr int not null, othr int not null, primary key(incr));
  57. CREATE TABLE t2 (incr int not null, othr int not null, primary key(incr));
  58. CREATE TABLE t3 (incr int not null, othr int not null, primary key(incr))
  59. TYPE=MERGE UNION=(t1,t2);
  60. SELECT * from t3;
  61. INSERT INTO t1 VALUES ( 1,10),( 3,53),( 5,21),( 7,12),( 9,17);
  62. INSERT INTO t2 VALUES ( 2,24),( 4,33),( 6,41),( 8,26),( 0,32);
  63. INSERT INTO t1 VALUES (11,20),(13,43),(15,11),(17,22),(19,37);
  64. INSERT INTO t2 VALUES (12,25),(14,31),(16,42),(18,27),(10,30);
  65. SELECT * from t3 where incr in (1,2,3,4) order by othr;
  66. alter table t3 UNION=(t1);
  67. select count(*) from t3;
  68. alter table t3 UNION=(t1,t2);
  69. select count(*) from t3;
  70. alter table t3 TYPE=MYISAM;
  71. select count(*) from t3;
  72. # Test that ALTER TABLE rembers the old UNION
  73. drop table t3;
  74. CREATE TABLE t3 (incr int not null, othr int not null, primary key(incr))
  75. TYPE=MERGE UNION=(t1,t2);
  76. show create table t3;
  77. alter table t3 drop primary key;
  78. show create table t3;
  79. drop table t3,t2,t1;
  80. #
  81. # Test table without unions
  82. #
  83. create table t1 (a int not null) type=merge;
  84. select * from t1;
  85. drop table t1;