You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

407 lines
9.0 KiB

20 years ago
  1. DROP TABLE IF EXISTS t1, t2, r1;
  2. create table t1 (
  3. a int primary key,
  4. b int not null,
  5. c int not null,
  6. index(b), unique index using hash(c)
  7. ) engine = ndb;
  8. insert into t1 values
  9. (1,2,1),(2,3,2),(3,4,3),(4,5,4),
  10. (5,2,12),(6,3,11),(7,4,10),(8,5,9),
  11. (9,2,8),(10,3,7),(11,4,6),(12,5,5);
  12. create table r1 as select * from t1 where a in (2,8,12);
  13. select * from r1 order by a;
  14. a b c
  15. 2 3 2
  16. 8 5 9
  17. 12 5 5
  18. drop table r1;
  19. create table r1 as select * from t1 where b in (1,2,5);
  20. select * from r1 order by a;
  21. a b c
  22. 1 2 1
  23. 4 5 4
  24. 5 2 12
  25. 8 5 9
  26. 9 2 8
  27. 12 5 5
  28. drop table r1;
  29. create table r1 as select * from t1 where c in (2,8,12);
  30. select * from r1 order by a;
  31. a b c
  32. 2 3 2
  33. 5 2 12
  34. 9 2 8
  35. drop table r1;
  36. create table r1 as select * from t1 where a in (2,8) or (a > 11) or (a <= 1);
  37. select * from r1 order by a;
  38. a b c
  39. 1 2 1
  40. 2 3 2
  41. 8 5 9
  42. 12 5 5
  43. drop table r1;
  44. create table r1 as select * from t1 where a in (33,8,12);
  45. select * from r1 order by a;
  46. a b c
  47. 8 5 9
  48. 12 5 5
  49. drop table r1;
  50. create table r1 as select * from t1 where a in (2,33,8,12,34);
  51. select * from r1 order by a;
  52. a b c
  53. 2 3 2
  54. 8 5 9
  55. 12 5 5
  56. drop table r1;
  57. create table r1 as select * from t1 where b in (1,33,5);
  58. select * from r1 order by a;
  59. a b c
  60. 4 5 4
  61. 8 5 9
  62. 12 5 5
  63. drop table r1;
  64. select * from t1 where b in (1,33,5) order by a;
  65. a b c
  66. 4 5 4
  67. 8 5 9
  68. 12 5 5
  69. create table r1 as select * from t1 where b in (45,1,33,5,44);
  70. select * from r1 order by a;
  71. a b c
  72. 4 5 4
  73. 8 5 9
  74. 12 5 5
  75. drop table r1;
  76. select * from t1 where b in (45,22) order by a;
  77. a b c
  78. create table r1 as select * from t1 where c in (2,8,33);
  79. select * from r1 order by a;
  80. a b c
  81. 2 3 2
  82. 9 2 8
  83. drop table r1;
  84. create table r1 as select * from t1 where c in (13,2,8,33,12);
  85. select * from r1 order by a;
  86. a b c
  87. 2 3 2
  88. 5 2 12
  89. 9 2 8
  90. drop table r1;
  91. select * from t1 where a in (33,8,12) order by a;
  92. a b c
  93. 8 5 9
  94. 12 5 5
  95. select * from t1 where a in (33,34,35) order by a;
  96. a b c
  97. select * from t1 where a in (2,8) or (a > 11) or (a <= 1) order by a;
  98. a b c
  99. 1 2 1
  100. 2 3 2
  101. 8 5 9
  102. 12 5 5
  103. select * from t1 where b in (6,7) or (b <= 5) or (b >= 10) order by b,a;
  104. a b c
  105. 1 2 1
  106. 5 2 12
  107. 9 2 8
  108. 2 3 2
  109. 6 3 11
  110. 10 3 7
  111. 3 4 3
  112. 7 4 10
  113. 11 4 6
  114. 4 5 4
  115. 8 5 9
  116. 12 5 5
  117. select * from t1 where c in (13,2,8,33,12) order by c,a;
  118. a b c
  119. 2 3 2
  120. 9 2 8
  121. 5 2 12
  122. drop table t1;
  123. create table t1 (
  124. a int not null,
  125. b int not null,
  126. c int not null,
  127. d int not null,
  128. e int not null,
  129. primary key (a,b,c,d), index (d)
  130. ) engine = ndb;
  131. insert into t1 values
  132. (1,2,1,1,1),(2,3,2,3,1),(3,4,3,1,1),(4,5,4,7,1),
  133. (5,2,12,12,1),(6,3,11,1,1),(7,4,10,3,1),(8,5,9,5,1),
  134. (9,2,8,6,1),(10,3,7,5,1),(11,4,6,3,1),(12,5,5,2,1),
  135. (1,2,1,2,1),
  136. (1,2,1,3,1),
  137. (1,2,1,4,1),
  138. (1,2,1,5,1);
  139. create table r1 as select * from t1
  140. where a=1 and b=2 and c=1 and d in (1,4,3,2);
  141. select * from r1 order by a,b,c,d;
  142. a b c d e
  143. 1 2 1 1 1
  144. 1 2 1 2 1
  145. 1 2 1 3 1
  146. 1 2 1 4 1
  147. drop table r1;
  148. update t1 set e = 100
  149. where d in (12,6,7);
  150. select * from t1 where d in (12,6,7) order by a,b,c,d;
  151. a b c d e
  152. 4 5 4 7 100
  153. 5 2 12 12 100
  154. 9 2 8 6 100
  155. select * from t1 where d not in (12,6,7) and e = 100;
  156. a b c d e
  157. update t1
  158. set e = 101
  159. where a=1 and
  160. b=2 and
  161. c=1 and
  162. d in (1,4,3,2);
  163. select *
  164. from t1
  165. where a=1 and b=2 and c=1 and d in (1,4,3,2)
  166. order by a,b,c,d;
  167. a b c d e
  168. 1 2 1 1 101
  169. 1 2 1 2 101
  170. 1 2 1 3 101
  171. 1 2 1 4 101
  172. select *
  173. from t1
  174. where not (a=1 and b=2 and c=1 and d in (1,4,3,2))
  175. and e=101;
  176. a b c d e
  177. update t1
  178. set e =
  179. (case d
  180. when 12 then 112
  181. when 6 then 106
  182. when 7 then 107
  183. end)
  184. where d in (12,6,7);
  185. select * from t1 where d in (12,6,7) order by a,b,c,d;
  186. a b c d e
  187. 4 5 4 7 107
  188. 5 2 12 12 112
  189. 9 2 8 6 106
  190. update t1
  191. set e =
  192. (case d
  193. when 1 then 111
  194. when 4 then 444
  195. when 3 then 333
  196. when 2 then 222
  197. end)
  198. where a=1 and
  199. b=2 and
  200. c=1 and
  201. d in (1,4,3,2);
  202. select *
  203. from t1
  204. where a=1 and b=2 and c=1 and d in (1,4,3,2)
  205. order by a,b,c,d;
  206. a b c d e
  207. 1 2 1 1 111
  208. 1 2 1 2 222
  209. 1 2 1 3 333
  210. 1 2 1 4 444
  211. delete from t1 where d in (12,6,7);
  212. select * from t1 where d in (12,6,7);
  213. a b c d e
  214. drop table t1;
  215. create table t1 (
  216. a int not null primary key,
  217. b int,
  218. c int,
  219. d int,
  220. unique index (b),
  221. index(c)
  222. ) engine = ndb;
  223. insert into t1 values
  224. (1,null,1,1),
  225. (2,2,2,2),
  226. (3,null,null,3),
  227. (4,4,null,4),
  228. (5,null,5,null),
  229. (6,6,6,null),
  230. (7,null,null,null),
  231. (8,8,null,null),
  232. (9,null,9,9),
  233. (10,10,10,10),
  234. (11,null,null,11),
  235. (12,12,null,12),
  236. (13,null,13,null),
  237. (14,14,14,null),
  238. (15,null,null,null),
  239. (16,16,null,null);
  240. create table t2 as select * from t1 where a in (5,6,7,8,9,10);
  241. select * from t2 order by a;
  242. a b c d
  243. 5 NULL 5 NULL
  244. 6 6 6 NULL
  245. 7 NULL NULL NULL
  246. 8 8 NULL NULL
  247. 9 NULL 9 9
  248. 10 10 10 10
  249. drop table t2;
  250. create table t2 as select * from t1 where b in (5,6,7,8,9,10);
  251. select * from t2 order by a;
  252. a b c d
  253. 6 6 6 NULL
  254. 8 8 NULL NULL
  255. 10 10 10 10
  256. drop table t2;
  257. create table t2 as select * from t1 where c in (5,6,7,8,9,10);
  258. select * from t2 order by a;
  259. a b c d
  260. 5 NULL 5 NULL
  261. 6 6 6 NULL
  262. 9 NULL 9 9
  263. 10 10 10 10
  264. drop table t2;
  265. drop table t1;
  266. CREATE TABLE t1 (
  267. a int(11) NOT NULL,
  268. b int(11) NOT NULL,
  269. c datetime default NULL,
  270. PRIMARY KEY (a),
  271. KEY idx_bc (b,c)
  272. ) ENGINE=ndbcluster;
  273. INSERT INTO t1 VALUES
  274. (406989,67,'2006-02-23 17:08:46'), (150078,67,'2005-10-26 11:17:45'),
  275. (406993,67,'2006-02-27 11:20:57'), (245655,67,'2005-12-08 15:59:08'),
  276. (406994,67,'2006-02-27 11:26:46'), (256,67,NULL),
  277. (398341,67,'2006-02-20 04:48:44'), (254,67,NULL),(1120,67,NULL),
  278. (406988,67,'2006-02-23 17:07:22'), (255,67,NULL),
  279. (398340,67,'2006-02-20 04:38:53'),(406631,67,'2006-02-23 10:49:42'),
  280. (245653,67,'2005-12-08 15:59:07'),(406992,67,'2006-02-24 16:47:18'),
  281. (245654,67,'2005-12-08 15:59:08'),(406995,67,'2006-02-28 11:55:00'),
  282. (127261,67,'2005-10-13 12:17:58'),(406991,67,'2006-02-24 16:42:32'),
  283. (245652,67,'2005-12-08 15:58:27'),(398545,67,'2006-02-20 04:53:13'),
  284. (154504,67,'2005-10-28 11:53:01'),(9199,67,NULL),(1,67,'2006-02-23 15:01:35'),
  285. (223456,67,NULL),(4101,67,NULL),(1133,67,NULL),
  286. (406990,67,'2006-02-23 18:01:45'),(148815,67,'2005-10-25 15:34:17'),
  287. (148812,67,'2005-10-25 15:30:01'),(245651,67,'2005-12-08 15:58:27'),
  288. (154503,67,'2005-10-28 11:52:38');
  289. create table t11 select * from t1 where b = 67 AND (c IS NULL OR c > NOW()) order by 3 asc;
  290. create table t12 select * from t1 where b = 67 AND (c IS NULL OR c > NOW()) order by 3 desc;
  291. create table t21 select * from t1 where b = 67 AND (c IS NULL OR c > '2005-12-08') order by 3 asc;
  292. create table t22 select * from t1 where b = 67 AND (c IS NULL OR c > '2005-12-08') order by 3 desc;
  293. select * from t11 order by 1,2,3;
  294. a b c
  295. 254 67 NULL
  296. 255 67 NULL
  297. 256 67 NULL
  298. 1120 67 NULL
  299. 1133 67 NULL
  300. 4101 67 NULL
  301. 9199 67 NULL
  302. 223456 67 NULL
  303. select * from t12 order by 1,2,3;
  304. a b c
  305. 254 67 NULL
  306. 255 67 NULL
  307. 256 67 NULL
  308. 1120 67 NULL
  309. 1133 67 NULL
  310. 4101 67 NULL
  311. 9199 67 NULL
  312. 223456 67 NULL
  313. select * from t21 order by 1,2,3;
  314. a b c
  315. 1 67 2006-02-23 15:01:35
  316. 254 67 NULL
  317. 255 67 NULL
  318. 256 67 NULL
  319. 1120 67 NULL
  320. 1133 67 NULL
  321. 4101 67 NULL
  322. 9199 67 NULL
  323. 223456 67 NULL
  324. 245651 67 2005-12-08 15:58:27
  325. 245652 67 2005-12-08 15:58:27
  326. 245653 67 2005-12-08 15:59:07
  327. 245654 67 2005-12-08 15:59:08
  328. 245655 67 2005-12-08 15:59:08
  329. 398340 67 2006-02-20 04:38:53
  330. 398341 67 2006-02-20 04:48:44
  331. 398545 67 2006-02-20 04:53:13
  332. 406631 67 2006-02-23 10:49:42
  333. 406988 67 2006-02-23 17:07:22
  334. 406989 67 2006-02-23 17:08:46
  335. 406990 67 2006-02-23 18:01:45
  336. 406991 67 2006-02-24 16:42:32
  337. 406992 67 2006-02-24 16:47:18
  338. 406993 67 2006-02-27 11:20:57
  339. 406994 67 2006-02-27 11:26:46
  340. 406995 67 2006-02-28 11:55:00
  341. select * from t22 order by 1,2,3;
  342. a b c
  343. 1 67 2006-02-23 15:01:35
  344. 254 67 NULL
  345. 255 67 NULL
  346. 256 67 NULL
  347. 1120 67 NULL
  348. 1133 67 NULL
  349. 4101 67 NULL
  350. 9199 67 NULL
  351. 223456 67 NULL
  352. 245651 67 2005-12-08 15:58:27
  353. 245652 67 2005-12-08 15:58:27
  354. 245653 67 2005-12-08 15:59:07
  355. 245654 67 2005-12-08 15:59:08
  356. 245655 67 2005-12-08 15:59:08
  357. 398340 67 2006-02-20 04:38:53
  358. 398341 67 2006-02-20 04:48:44
  359. 398545 67 2006-02-20 04:53:13
  360. 406631 67 2006-02-23 10:49:42
  361. 406988 67 2006-02-23 17:07:22
  362. 406989 67 2006-02-23 17:08:46
  363. 406990 67 2006-02-23 18:01:45
  364. 406991 67 2006-02-24 16:42:32
  365. 406992 67 2006-02-24 16:47:18
  366. 406993 67 2006-02-27 11:20:57
  367. 406994 67 2006-02-27 11:26:46
  368. 406995 67 2006-02-28 11:55:00
  369. DROP TABLE t1, t11, t12, t21, t22;
  370. CREATE TABLE t1 (id varchar(255) NOT NULL,
  371. tag int(11) NOT NULL,
  372. doc text NOT NULL,
  373. type varchar(150) NOT NULL,
  374. modified timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  375. PRIMARY KEY (id)
  376. ) ENGINE=ndbcluster;
  377. INSERT INTO t1 VALUES ('sakila',1,'Some text goes here','text',CURRENT_TIMESTAMP);
  378. SELECT id, tag, doc, type FROM t1 WHERE id IN ('flipper','orka');
  379. id tag doc type
  380. SELECT id, tag, doc, type FROM t1 WHERE id IN ('flipper','sakila');
  381. id tag doc type
  382. sakila 1 Some text goes here text
  383. DROP TABLE t1;
  384. CREATE TABLE t1 (
  385. var1 int(2) NOT NULL,
  386. var2 int(2) NOT NULL,
  387. PRIMARY KEY (var1)
  388. ) ENGINE=ndbcluster DEFAULT CHARSET=ascii CHECKSUM=1;
  389. CREATE TABLE t2 (
  390. var1 int(2) NOT NULL,
  391. var2 int(2) NOT NULL,
  392. PRIMARY KEY (var1)
  393. ) ENGINE=MyISAM DEFAULT CHARSET=ascii CHECKSUM=1;
  394. CREATE TRIGGER testtrigger
  395. AFTER UPDATE ON t1 FOR EACH ROW BEGIN
  396. REPLACE INTO t2 SELECT * FROM t1 WHERE t1.var1 = NEW.var1;END|
  397. INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
  398. UPDATE t1 SET var2 = 9 WHERE var1 IN(1,2,3);
  399. DROP TRIGGER testtrigger;
  400. DROP TABLE t1, t2;
  401. create table t2 (a int, b int, primary key (a), key ab (a,b)) engine=ndbcluster;
  402. insert into t2 values (1,1), (10,10);
  403. select * from t2 use index (ab) where a in(1,10) order by a;
  404. a b
  405. 1 1
  406. 10 10
  407. drop table t2;