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.

668 lines
14 KiB

22 years ago
22 years ago
  1. drop table if exists t1, test1, test2;
  2. CREATE TABLE t1 (
  3. a int unsigned NOT NULL PRIMARY KEY,
  4. b int unsigned not null,
  5. c int unsigned,
  6. KEY(b)
  7. ) engine=ndbcluster;
  8. insert t1 values(1, 2, 3), (2,3, 5), (3, 4, 6), (4, 5, 8), (5,6, 2), (6,7, 2);
  9. select * from t1 order by b;
  10. a b c
  11. 1 2 3
  12. 2 3 5
  13. 3 4 6
  14. 4 5 8
  15. 5 6 2
  16. 6 7 2
  17. select * from t1 where b >= 4 order by b;
  18. a b c
  19. 3 4 6
  20. 4 5 8
  21. 5 6 2
  22. 6 7 2
  23. select * from t1 where b = 4 order by b;
  24. a b c
  25. 3 4 6
  26. select * from t1 where b > 4 order by b;
  27. a b c
  28. 4 5 8
  29. 5 6 2
  30. 6 7 2
  31. select * from t1 where b < 4 order by b;
  32. a b c
  33. 1 2 3
  34. 2 3 5
  35. select * from t1 where b <= 4 order by b;
  36. a b c
  37. 1 2 3
  38. 2 3 5
  39. 3 4 6
  40. select tt1.* from t1 as tt1, t1 as tt2 use index(b) where tt1.b = tt2.b order by tt1.b;
  41. a b c
  42. 1 2 3
  43. 2 3 5
  44. 3 4 6
  45. 4 5 8
  46. 5 6 2
  47. 6 7 2
  48. select a, b, c from t1 where a!=2 and c=6;
  49. a b c
  50. 3 4 6
  51. select a, b, c from t1 where a!=2 order by a;
  52. a b c
  53. 1 2 3
  54. 3 4 6
  55. 4 5 8
  56. 5 6 2
  57. 6 7 2
  58. update t1 set c = 3 where b = 3;
  59. select * from t1 order by a;
  60. a b c
  61. 1 2 3
  62. 2 3 3
  63. 3 4 6
  64. 4 5 8
  65. 5 6 2
  66. 6 7 2
  67. update t1 set c = 10 where b >= 6;
  68. select * from t1 order by a;
  69. a b c
  70. 1 2 3
  71. 2 3 3
  72. 3 4 6
  73. 4 5 8
  74. 5 6 10
  75. 6 7 10
  76. update t1 set c = 11 where b < 5;
  77. select * from t1 order by a;
  78. a b c
  79. 1 2 11
  80. 2 3 11
  81. 3 4 11
  82. 4 5 8
  83. 5 6 10
  84. 6 7 10
  85. update t1 set c = 12 where b > 0;
  86. select * from t1 order by a;
  87. a b c
  88. 1 2 12
  89. 2 3 12
  90. 3 4 12
  91. 4 5 12
  92. 5 6 12
  93. 6 7 12
  94. update t1 set c = 13 where b <= 3;
  95. select * from t1 order by a;
  96. a b c
  97. 1 2 13
  98. 2 3 13
  99. 3 4 12
  100. 4 5 12
  101. 5 6 12
  102. 6 7 12
  103. update t1 set b = b + 1 where b > 4 and b < 7;
  104. select * from t1 order by a;
  105. a b c
  106. 1 2 13
  107. 2 3 13
  108. 3 4 12
  109. 4 6 12
  110. 5 7 12
  111. 6 7 12
  112. update t1 set a = a + 10 where b > 1 and b < 7;
  113. select * from t1 order by a;
  114. a b c
  115. 5 7 12
  116. 6 7 12
  117. 11 2 13
  118. 12 3 13
  119. 13 4 12
  120. 14 6 12
  121. drop table t1;
  122. CREATE TABLE t1 (
  123. a int unsigned NOT NULL PRIMARY KEY,
  124. b int unsigned not null,
  125. c int unsigned,
  126. KEY(b)
  127. ) engine=ndbcluster;
  128. insert t1 values(1, 2, 13), (2,3, 13), (3, 4, 12), (4, 5, 12), (5,6, 12), (6,7, 12);
  129. delete from t1 where b = 3;
  130. select * from t1 order by a;
  131. a b c
  132. 1 2 13
  133. 3 4 12
  134. 4 5 12
  135. 5 6 12
  136. 6 7 12
  137. delete from t1 where b >= 6;
  138. select * from t1 order by a;
  139. a b c
  140. 1 2 13
  141. 3 4 12
  142. 4 5 12
  143. delete from t1 where b < 4;
  144. select * from t1 order by a;
  145. a b c
  146. 3 4 12
  147. 4 5 12
  148. delete from t1 where b > 5;
  149. select * from t1 order by a;
  150. a b c
  151. 3 4 12
  152. 4 5 12
  153. delete from t1 where b <= 4;
  154. select * from t1 order by a;
  155. a b c
  156. 4 5 12
  157. drop table t1;
  158. CREATE TABLE t1 (
  159. a int unsigned NOT NULL PRIMARY KEY,
  160. b int unsigned not null,
  161. c int unsigned not null
  162. ) engine = ndb;
  163. create index a1 on t1 (b, c);
  164. insert into t1 values (1, 2, 13);
  165. insert into t1 values (2,3, 13);
  166. insert into t1 values (3, 4, 12);
  167. insert into t1 values (4, 5, 12);
  168. insert into t1 values (5,6, 12);
  169. insert into t1 values (6,7, 12);
  170. insert into t1 values (7, 2, 1);
  171. insert into t1 values (8,3, 6);
  172. insert into t1 values (9, 4, 12);
  173. insert into t1 values (14, 5, 4);
  174. insert into t1 values (15,5,5);
  175. insert into t1 values (16,5, 6);
  176. insert into t1 values (17,4,4);
  177. insert into t1 values (18,1, 7);
  178. select * from t1 order by a;
  179. a b c
  180. 1 2 13
  181. 2 3 13
  182. 3 4 12
  183. 4 5 12
  184. 5 6 12
  185. 6 7 12
  186. 7 2 1
  187. 8 3 6
  188. 9 4 12
  189. 14 5 4
  190. 15 5 5
  191. 16 5 6
  192. 17 4 4
  193. 18 1 7
  194. select * from t1 where b<=5 order by a;
  195. a b c
  196. 1 2 13
  197. 2 3 13
  198. 3 4 12
  199. 4 5 12
  200. 7 2 1
  201. 8 3 6
  202. 9 4 12
  203. 14 5 4
  204. 15 5 5
  205. 16 5 6
  206. 17 4 4
  207. 18 1 7
  208. select * from t1 where b<=5 and c=0;
  209. a b c
  210. insert into t1 values (19,4, 0);
  211. select * from t1 where b<=5 and c=0;
  212. a b c
  213. 19 4 0
  214. select * from t1 where b=4 and c<=5 order by a;
  215. a b c
  216. 17 4 4
  217. 19 4 0
  218. select * from t1 where b<=4 and c<=5 order by a;
  219. a b c
  220. 7 2 1
  221. 17 4 4
  222. 19 4 0
  223. select * from t1 where b<=5 and c=0 or b<=5 and c=2;
  224. a b c
  225. 19 4 0
  226. select count(*) from t1 where b = 0;
  227. count(*)
  228. 0
  229. select count(*) from t1 where b = 1;
  230. count(*)
  231. 1
  232. drop table t1;
  233. CREATE TABLE t1 (
  234. a int unsigned NOT NULL PRIMARY KEY,
  235. b int unsigned,
  236. c int unsigned,
  237. KEY bc(b,c)
  238. ) engine = ndb;
  239. insert into t1 values(1,1,1),(2,NULL,2),(3,NULL,NULL),(4,4,NULL);
  240. select * from t1 use index (bc) where b IS NULL order by a;
  241. a b c
  242. 2 NULL 2
  243. 3 NULL NULL
  244. select * from t1 use index (bc)order by a;
  245. a b c
  246. 1 1 1
  247. 2 NULL 2
  248. 3 NULL NULL
  249. 4 4 NULL
  250. select * from t1 use index (bc) order by a;
  251. a b c
  252. 1 1 1
  253. 2 NULL 2
  254. 3 NULL NULL
  255. 4 4 NULL
  256. select * from t1 use index (PRIMARY) where b IS NULL order by a;
  257. a b c
  258. 2 NULL 2
  259. 3 NULL NULL
  260. select * from t1 use index (bc) where b IS NULL order by a;
  261. a b c
  262. 2 NULL 2
  263. 3 NULL NULL
  264. select * from t1 use index (bc) where b IS NULL and c IS NULL order by a;
  265. a b c
  266. 3 NULL NULL
  267. select * from t1 use index (bc) where b IS NULL and c = 2 order by a;
  268. a b c
  269. 2 NULL 2
  270. select * from t1 use index (bc) where b < 4 order by a;
  271. a b c
  272. 1 1 1
  273. select * from t1 use index (bc) where b IS NOT NULL order by a;
  274. a b c
  275. 1 1 1
  276. 4 4 NULL
  277. drop table t1;
  278. create table t1 (
  279. a int unsigned primary key,
  280. b int unsigned,
  281. c char(10),
  282. key bc (b, c)
  283. ) engine=ndb;
  284. insert into t1 values(1,1,'a'),(2,2,'b'),(3,3,'c'),(4,4,'d'),(5,5,'e');
  285. insert into t1 select a*7,10*b,'f' from t1;
  286. insert into t1 select a*13,10*b,'g' from t1;
  287. insert into t1 select a*17,10*b,'h' from t1;
  288. insert into t1 select a*19,10*b,'i' from t1;
  289. insert into t1 select a*23,10*b,'j' from t1;
  290. insert into t1 select a*29,10*b,'k' from t1;
  291. select b, c from t1 where b <= 10 and c <'f' order by b, c;
  292. b c
  293. 1 a
  294. 2 b
  295. 3 c
  296. 4 d
  297. 5 e
  298. select b, c from t1 where b <= 10 and c <'f' order by b desc, c desc;
  299. b c
  300. 5 e
  301. 4 d
  302. 3 c
  303. 2 b
  304. 1 a
  305. select b, c from t1 where b=4000 and c<'k' order by b, c;
  306. b c
  307. 4000 h
  308. 4000 i
  309. 4000 i
  310. 4000 i
  311. 4000 j
  312. 4000 j
  313. 4000 j
  314. 4000 j
  315. 4000 j
  316. 4000 j
  317. select b, c from t1 where b=4000 and c<'k' order by b desc, c desc;
  318. b c
  319. 4000 j
  320. 4000 j
  321. 4000 j
  322. 4000 j
  323. 4000 j
  324. 4000 j
  325. 4000 i
  326. 4000 i
  327. 4000 i
  328. 4000 h
  329. select b, c from t1 where 1000<=b and b<=100000 and c<'j' order by b, c;
  330. b c
  331. 1000 h
  332. 1000 i
  333. 1000 i
  334. 1000 i
  335. 2000 h
  336. 2000 i
  337. 2000 i
  338. 2000 i
  339. 3000 h
  340. 3000 i
  341. 3000 i
  342. 3000 i
  343. 4000 h
  344. 4000 i
  345. 4000 i
  346. 4000 i
  347. 5000 h
  348. 5000 i
  349. 5000 i
  350. 5000 i
  351. 10000 i
  352. 20000 i
  353. 30000 i
  354. 40000 i
  355. 50000 i
  356. select b, c from t1 where 1000<=b and b<=100000 and c<'j' order by b desc, c desc;
  357. b c
  358. 50000 i
  359. 40000 i
  360. 30000 i
  361. 20000 i
  362. 10000 i
  363. 5000 i
  364. 5000 i
  365. 5000 i
  366. 5000 h
  367. 4000 i
  368. 4000 i
  369. 4000 i
  370. 4000 h
  371. 3000 i
  372. 3000 i
  373. 3000 i
  374. 3000 h
  375. 2000 i
  376. 2000 i
  377. 2000 i
  378. 2000 h
  379. 1000 i
  380. 1000 i
  381. 1000 i
  382. 1000 h
  383. select min(b), max(b) from t1;
  384. min(b) max(b)
  385. 1 5000000
  386. drop table t1;
  387. CREATE TABLE test1 (
  388. SubscrID int(11) NOT NULL auto_increment,
  389. UsrID int(11) NOT NULL default '0',
  390. PRIMARY KEY (SubscrID),
  391. KEY idx_usrid (UsrID)
  392. ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
  393. INSERT INTO test1 VALUES (2,224),(3,224),(1,224);
  394. CREATE TABLE test2 (
  395. SbclID int(11) NOT NULL auto_increment,
  396. SbcrID int(11) NOT NULL default '0',
  397. PRIMARY KEY (SbclID),
  398. KEY idx_sbcrid (SbcrID)
  399. ) ENGINE=ndbcluster DEFAULT CHARSET=latin1;
  400. INSERT INTO test2 VALUES (3,2),(1,1),(2,1),(4,2);
  401. select * from test1 order by 1;
  402. SubscrID UsrID
  403. 1 224
  404. 2 224
  405. 3 224
  406. select * from test2 order by 1;
  407. SbclID SbcrID
  408. 1 1
  409. 2 1
  410. 3 2
  411. 4 2
  412. SELECT s.SubscrID,l.SbclID FROM test1 s left JOIN test2 l ON
  413. l.SbcrID=s.SubscrID WHERE s.UsrID=224 order by 1, 2;
  414. SubscrID SbclID
  415. 1 1
  416. 1 2
  417. 2 3
  418. 2 4
  419. 3 NULL
  420. drop table test1;
  421. drop table test2;
  422. create table t1 (
  423. pk int primary key,
  424. dt datetime not null,
  425. da date not null,
  426. ye year not null,
  427. ti time not null,
  428. ts timestamp not null,
  429. index(dt),
  430. index(da),
  431. index(ye),
  432. index(ti),
  433. index(ts)
  434. ) engine=ndb;
  435. insert into t1 (pk,dt,da,ye,ti,ts) values
  436. (1, '1901-05-05 23:00:59', '1901-05-05', '1901', '23:00:59', '2001-01-01 23:00:59'),
  437. (2, '1912-09-05 13:00:59', '1912-09-05', '1912', '13:00:59', '2001-01-01 13:00:59'),
  438. (3, '1945-12-31 00:00:00', '1945-12-31', '1945', '00:00:00', '2001-01-01 00:00:00'),
  439. (4, '1955-12-31 00:00:00', '1955-12-31', '1955', '00:00:00', '2001-01-01 00:00:00'),
  440. (5, '1963-06-06 06:06:06', '1963-06-06', '1963', '06:06:06', '2001-01-01 06:06:06'),
  441. (6, '1993-06-06 06:06:06', '1993-06-06', '1993', '06:06:06', '2001-01-01 06:06:06'),
  442. (7, '2001-01-01 10:11:10', '2001-01-01', '2001', '10:11:10', '2001-01-01 10:11:10'),
  443. (8, '2001-01-01 10:11:11', '2001-01-01', '2001', '10:11:11', '2001-01-01 10:11:11'),
  444. (9, '2005-01-31 23:59:59', '2005-01-31', '2005', '23:59:59', '2001-01-01 23:59:59');
  445. select count(*)-9 from t1 use index (dt) where dt > '1900-01-01 00:00:00';
  446. count(*)-9
  447. 0
  448. select count(*)-6 from t1 use index (dt) where dt >= '1955-12-31 00:00:00';
  449. count(*)-6
  450. 0
  451. select count(*)-5 from t1 use index (dt) where dt > '1955-12-31 00:00:00';
  452. count(*)-5
  453. 0
  454. select count(*)-5 from t1 use index (dt) where dt < '1970-03-03 22:22:22';
  455. count(*)-5
  456. 0
  457. select count(*)-7 from t1 use index (dt) where dt < '2001-01-01 10:11:11';
  458. count(*)-7
  459. 0
  460. select count(*)-8 from t1 use index (dt) where dt <= '2001-01-01 10:11:11';
  461. count(*)-8
  462. 0
  463. select count(*)-9 from t1 use index (dt) where dt <= '2055-01-01 00:00:00';
  464. count(*)-9
  465. 0
  466. select count(*)-9 from t1 use index (da) where da > '1900-01-01';
  467. count(*)-9
  468. 0
  469. select count(*)-6 from t1 use index (da) where da >= '1955-12-31';
  470. count(*)-6
  471. 0
  472. select count(*)-5 from t1 use index (da) where da > '1955-12-31';
  473. count(*)-5
  474. 0
  475. select count(*)-5 from t1 use index (da) where da < '1970-03-03';
  476. count(*)-5
  477. 0
  478. select count(*)-6 from t1 use index (da) where da < '2001-01-01';
  479. count(*)-6
  480. 0
  481. select count(*)-8 from t1 use index (da) where da <= '2001-01-02';
  482. count(*)-8
  483. 0
  484. select count(*)-9 from t1 use index (da) where da <= '2055-01-01';
  485. count(*)-9
  486. 0
  487. select count(*)-9 from t1 use index (ye) where ye > '1900';
  488. count(*)-9
  489. 0
  490. select count(*)-6 from t1 use index (ye) where ye >= '1955';
  491. count(*)-6
  492. 0
  493. select count(*)-5 from t1 use index (ye) where ye > '1955';
  494. count(*)-5
  495. 0
  496. select count(*)-5 from t1 use index (ye) where ye < '1970';
  497. count(*)-5
  498. 0
  499. select count(*)-6 from t1 use index (ye) where ye < '2001';
  500. count(*)-6
  501. 0
  502. select count(*)-8 from t1 use index (ye) where ye <= '2001';
  503. count(*)-8
  504. 0
  505. select count(*)-9 from t1 use index (ye) where ye <= '2055';
  506. count(*)-9
  507. 0
  508. select count(*)-9 from t1 use index (ti) where ti >= '00:00:00';
  509. count(*)-9
  510. 0
  511. select count(*)-7 from t1 use index (ti) where ti > '00:00:00';
  512. count(*)-7
  513. 0
  514. select count(*)-7 from t1 use index (ti) where ti > '05:05:05';
  515. count(*)-7
  516. 0
  517. select count(*)-5 from t1 use index (ti) where ti > '06:06:06';
  518. count(*)-5
  519. 0
  520. select count(*)-5 from t1 use index (ti) where ti < '10:11:11';
  521. count(*)-5
  522. 0
  523. select count(*)-6 from t1 use index (ti) where ti <= '10:11:11';
  524. count(*)-6
  525. 0
  526. select count(*)-8 from t1 use index (ti) where ti < '23:59:59';
  527. count(*)-8
  528. 0
  529. select count(*)-9 from t1 use index (ti) where ti <= '23:59:59';
  530. count(*)-9
  531. 0
  532. select count(*)-9 from t1 use index (ts) where ts >= '2001-01-01 00:00:00';
  533. count(*)-9
  534. 0
  535. select count(*)-7 from t1 use index (ts) where ts > '2001-01-01 00:00:00';
  536. count(*)-7
  537. 0
  538. select count(*)-7 from t1 use index (ts) where ts > '2001-01-01 05:05:05';
  539. count(*)-7
  540. 0
  541. select count(*)-5 from t1 use index (ts) where ts > '2001-01-01 06:06:06';
  542. count(*)-5
  543. 0
  544. select count(*)-5 from t1 use index (ts) where ts < '2001-01-01 10:11:11';
  545. count(*)-5
  546. 0
  547. select count(*)-6 from t1 use index (ts) where ts <= '2001-01-01 10:11:11';
  548. count(*)-6
  549. 0
  550. select count(*)-8 from t1 use index (ts) where ts < '2001-01-01 23:59:59';
  551. count(*)-8
  552. 0
  553. select count(*)-9 from t1 use index (ts) where ts <= '2001-01-01 23:59:59';
  554. count(*)-9
  555. 0
  556. drop table t1;
  557. create table t1 (
  558. a int primary key,
  559. s decimal(12),
  560. t decimal(12, 5),
  561. u decimal(12) unsigned,
  562. v decimal(12, 5) unsigned,
  563. key (s),
  564. key (t),
  565. key (u),
  566. key (v)
  567. ) engine=ndb;
  568. insert into t1 values
  569. ( 0, -000000000007, -0000061.00003, 000000000061, 0000965.00042),
  570. ( 1, -000000000007, -0000061.00042, 000000000061, 0000965.00003),
  571. ( 2, -071006035767, 4210253.00024, 000000000001, 0000001.84488),
  572. ( 3, 000000007115, 0000000.77607, 000077350625, 0000018.00013),
  573. ( 4, -000000068391, -0346486.00000, 000000005071, 0005334.00002),
  574. ( 5, -521579890459, -1936874.00001, 000000000154, 0000003.00018),
  575. ( 6, -521579890459, -1936874.00018, 000000000154, 0000003.00001),
  576. ( 7, 000000000333, 0000051.39140, 000000907958, 0788643.08374),
  577. ( 8, 000042731229, 0000009.00000, 000000000009, 6428667.00000),
  578. ( 9, -000008159769, 0000918.00004, 000096951421, 7607730.00008);
  579. select count(*)- 5 from t1 use index (s) where s < -000000000007;
  580. count(*)- 5
  581. 0
  582. select count(*)- 7 from t1 use index (s) where s <= -000000000007;
  583. count(*)- 7
  584. 0
  585. select count(*)- 2 from t1 use index (s) where s = -000000000007;
  586. count(*)- 2
  587. 0
  588. select count(*)- 5 from t1 use index (s) where s >= -000000000007;
  589. count(*)- 5
  590. 0
  591. select count(*)- 3 from t1 use index (s) where s > -000000000007;
  592. count(*)- 3
  593. 0
  594. select count(*)- 4 from t1 use index (t) where t < -0000061.00003;
  595. count(*)- 4
  596. 0
  597. select count(*)- 5 from t1 use index (t) where t <= -0000061.00003;
  598. count(*)- 5
  599. 0
  600. select count(*)- 1 from t1 use index (t) where t = -0000061.00003;
  601. count(*)- 1
  602. 0
  603. select count(*)- 6 from t1 use index (t) where t >= -0000061.00003;
  604. count(*)- 6
  605. 0
  606. select count(*)- 5 from t1 use index (t) where t > -0000061.00003;
  607. count(*)- 5
  608. 0
  609. select count(*)- 2 from t1 use index (u) where u < 000000000061;
  610. count(*)- 2
  611. 0
  612. select count(*)- 4 from t1 use index (u) where u <= 000000000061;
  613. count(*)- 4
  614. 0
  615. select count(*)- 2 from t1 use index (u) where u = 000000000061;
  616. count(*)- 2
  617. 0
  618. select count(*)- 8 from t1 use index (u) where u >= 000000000061;
  619. count(*)- 8
  620. 0
  621. select count(*)- 6 from t1 use index (u) where u > 000000000061;
  622. count(*)- 6
  623. 0
  624. select count(*)- 5 from t1 use index (v) where v < 0000965.00042;
  625. count(*)- 5
  626. 0
  627. select count(*)- 6 from t1 use index (v) where v <= 0000965.00042;
  628. count(*)- 6
  629. 0
  630. select count(*)- 1 from t1 use index (v) where v = 0000965.00042;
  631. count(*)- 1
  632. 0
  633. select count(*)- 5 from t1 use index (v) where v >= 0000965.00042;
  634. count(*)- 5
  635. 0
  636. select count(*)- 4 from t1 use index (v) where v > 0000965.00042;
  637. count(*)- 4
  638. 0
  639. drop table t1;
  640. create table t1(a int primary key, b int not null, index(b));
  641. insert into t1 values (1,1), (2,2);
  642. set autocommit=0;
  643. begin;
  644. select count(*) from t1;
  645. count(*)
  646. 2
  647. ALTER TABLE t1 ADD COLUMN c int;
  648. select a from t1 where b = 2;
  649. a
  650. 2
  651. show tables;
  652. Tables_in_test
  653. t1
  654. drop table t1;
  655. create table t1 (a int, c varchar(10),
  656. primary key using hash (a), index(c)) engine=ndb;
  657. insert into t1 (a, c) values (1,'aaa'),(3,'bbb');
  658. select count(*) from t1 where c<'bbb';
  659. count(*)
  660. 1
  661. create table nationaldish (DishID int(10) unsigned NOT NULL AUTO_INCREMENT,
  662. CountryCode char(3) NOT NULL,
  663. DishTitle varchar(64) NOT NULL,
  664. calories smallint(5) unsigned DEFAULT NULL,
  665. PRIMARY KEY (DishID),
  666. INDEX i USING HASH (countrycode,calories)
  667. ) ENGINE=ndbcluster;
  668. ERROR HY000: Can't create table './test/nationaldish.frm' (errno: 138)