join.out 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. --
  2. -- JOIN
  3. -- Test JOIN clauses
  4. --
  5. CREATE TABLE J1_TBL (
  6. i integer,
  7. j integer,
  8. t text
  9. );
  10. CREATE TABLE J2_TBL (
  11. i integer,
  12. k integer
  13. );
  14. INSERT INTO J1_TBL VALUES (1, 4, 'one');
  15. INSERT INTO J1_TBL VALUES (2, 3, 'two');
  16. INSERT INTO J1_TBL VALUES (3, 2, 'three');
  17. INSERT INTO J1_TBL VALUES (4, 1, 'four');
  18. INSERT INTO J1_TBL VALUES (5, 0, 'five');
  19. INSERT INTO J1_TBL VALUES (6, 6, 'six');
  20. INSERT INTO J1_TBL VALUES (7, 7, 'seven');
  21. INSERT INTO J1_TBL VALUES (8, 8, 'eight');
  22. INSERT INTO J1_TBL VALUES (0, NULL, 'zero');
  23. INSERT INTO J1_TBL VALUES (NULL, NULL, 'null');
  24. INSERT INTO J1_TBL VALUES (NULL, 0, 'zero');
  25. INSERT INTO J2_TBL VALUES (1, -1);
  26. INSERT INTO J2_TBL VALUES (2, 2);
  27. INSERT INTO J2_TBL VALUES (3, -3);
  28. INSERT INTO J2_TBL VALUES (2, 4);
  29. INSERT INTO J2_TBL VALUES (5, -5);
  30. INSERT INTO J2_TBL VALUES (5, -5);
  31. INSERT INTO J2_TBL VALUES (0, NULL);
  32. INSERT INTO J2_TBL VALUES (NULL, NULL);
  33. INSERT INTO J2_TBL VALUES (NULL, 0);
  34. -- useful in some tests below
  35. create temp table onerow();
  36. --
  37. -- CORRELATION NAMES
  38. -- Make sure that table/column aliases are supported
  39. -- before diving into more complex join syntax.
  40. --
  41. SELECT *
  42. FROM J1_TBL AS tx;
  43. i | j | t
  44. ---+---+-------
  45. 1 | 4 | one
  46. 2 | 3 | two
  47. 3 | 2 | three
  48. 4 | 1 | four
  49. 5 | 0 | five
  50. 6 | 6 | six
  51. 7 | 7 | seven
  52. 8 | 8 | eight
  53. 0 | | zero
  54. | | null
  55. | 0 | zero
  56. (11 rows)
  57. SELECT *
  58. FROM J1_TBL tx;
  59. i | j | t
  60. ---+---+-------
  61. 1 | 4 | one
  62. 2 | 3 | two
  63. 3 | 2 | three
  64. 4 | 1 | four
  65. 5 | 0 | five
  66. 6 | 6 | six
  67. 7 | 7 | seven
  68. 8 | 8 | eight
  69. 0 | | zero
  70. | | null
  71. | 0 | zero
  72. (11 rows)
  73. SELECT *
  74. FROM J1_TBL AS t1 (a, b, c);
  75. a | b | c
  76. ---+---+-------
  77. 1 | 4 | one
  78. 2 | 3 | two
  79. 3 | 2 | three
  80. 4 | 1 | four
  81. 5 | 0 | five
  82. 6 | 6 | six
  83. 7 | 7 | seven
  84. 8 | 8 | eight
  85. 0 | | zero
  86. | | null
  87. | 0 | zero
  88. (11 rows)
  89. SELECT *
  90. FROM J1_TBL t1 (a, b, c);
  91. a | b | c
  92. ---+---+-------
  93. 1 | 4 | one
  94. 2 | 3 | two
  95. 3 | 2 | three
  96. 4 | 1 | four
  97. 5 | 0 | five
  98. 6 | 6 | six
  99. 7 | 7 | seven
  100. 8 | 8 | eight
  101. 0 | | zero
  102. | | null
  103. | 0 | zero
  104. (11 rows)
  105. SELECT *
  106. FROM J1_TBL t1 (a, b, c) JOIN J2_TBL t2 (a, d) USING (a)
  107. ORDER BY a, d;
  108. a | b | c | d
  109. ---+---+-------+----
  110. 0 | | zero |
  111. 1 | 4 | one | -1
  112. 2 | 3 | two | 2
  113. 2 | 3 | two | 4
  114. 3 | 2 | three | -3
  115. 5 | 0 | five | -5
  116. 5 | 0 | five | -5
  117. (7 rows)
  118. -- test join using aliases
  119. SELECT * FROM J1_TBL JOIN J2_TBL USING (i) WHERE J1_TBL.t = 'one'; -- ok
  120. i | j | t | k
  121. ---+---+-----+----
  122. 1 | 4 | one | -1
  123. (1 row)
  124. SELECT *
  125. FROM J1_TBL LEFT JOIN J2_TBL USING (i) WHERE (k = 1);
  126. i | j | t | k
  127. ---+---+---+---
  128. (0 rows)
  129. --
  130. -- More complicated constructs
  131. --
  132. --
  133. -- Multiway full join
  134. --
  135. CREATE TABLE t1 (name TEXT, n INTEGER);
  136. CREATE TABLE t2 (name TEXT, n INTEGER);
  137. CREATE TABLE t3 (name TEXT, n INTEGER);
  138. INSERT INTO t1 VALUES ( 'bb', 11 );
  139. INSERT INTO t2 VALUES ( 'bb', 12 );
  140. INSERT INTO t2 VALUES ( 'cc', 22 );
  141. INSERT INTO t2 VALUES ( 'ee', 42 );
  142. INSERT INTO t3 VALUES ( 'bb', 13 );
  143. INSERT INTO t3 VALUES ( 'cc', 23 );
  144. INSERT INTO t3 VALUES ( 'dd', 33 );
  145. -- Test for propagation of nullability constraints into sub-joins
  146. create temp table x (x1 int, x2 int);
  147. insert into x values (1,11);
  148. insert into x values (2,22);
  149. insert into x values (3,null);
  150. insert into x values (4,44);
  151. insert into x values (5,null);
  152. create temp table y (y1 int, y2 int);
  153. insert into y values (1,111);
  154. insert into y values (2,222);
  155. insert into y values (3,333);
  156. insert into y values (4,null);
  157. select * from x;
  158. x1 | x2
  159. ----+----
  160. 1 | 11
  161. 2 | 22
  162. 3 |
  163. 4 | 44
  164. 5 |
  165. (5 rows)
  166. select * from y;
  167. y1 | y2
  168. ----+-----
  169. 1 | 111
  170. 2 | 222
  171. 3 | 333
  172. 4 |
  173. (4 rows)
  174. select * from (x left join y on (x1 = y1)) left join x xx(xx1,xx2)
  175. on (x1 = xx1);
  176. x1 | x2 | y1 | y2 | xx1 | xx2
  177. ----+----+----+-----+-----+-----
  178. 1 | 11 | 1 | 111 | 1 | 11
  179. 2 | 22 | 2 | 222 | 2 | 22
  180. 3 | | 3 | 333 | 3 |
  181. 4 | 44 | 4 | | 4 | 44
  182. 5 | | | | 5 |
  183. (5 rows)
  184. select * from (x left join y on (x1 = y1)) left join x xx(xx1,xx2)
  185. on (x1 = xx1 and xx2 is not null);
  186. x1 | x2 | y1 | y2 | xx1 | xx2
  187. ----+----+----+-----+-----+-----
  188. 1 | 11 | 1 | 111 | 1 | 11
  189. 2 | 22 | 2 | 222 | 2 | 22
  190. 3 | | 3 | 333 | |
  191. 4 | 44 | 4 | | 4 | 44
  192. 5 | | | | |
  193. (5 rows)
  194. -- these should NOT give the same answers as above
  195. select * from (x left join y on (x1 = y1)) left join x xx(xx1,xx2)
  196. on (x1 = xx1) where (x2 is not null);
  197. x1 | x2 | y1 | y2 | xx1 | xx2
  198. ----+----+----+-----+-----+-----
  199. 1 | 11 | 1 | 111 | 1 | 11
  200. 2 | 22 | 2 | 222 | 2 | 22
  201. 4 | 44 | 4 | | 4 | 44
  202. (3 rows)
  203. select * from (x left join y on (x1 = y1)) left join x xx(xx1,xx2)
  204. on (x1 = xx1) where (y2 is not null);
  205. x1 | x2 | y1 | y2 | xx1 | xx2
  206. ----+----+----+-----+-----+-----
  207. 1 | 11 | 1 | 111 | 1 | 11
  208. 2 | 22 | 2 | 222 | 2 | 22
  209. 3 | | 3 | 333 | 3 |
  210. (3 rows)
  211. select * from (x left join y on (x1 = y1)) left join x xx(xx1,xx2)
  212. on (x1 = xx1) where (xx2 is not null);
  213. x1 | x2 | y1 | y2 | xx1 | xx2
  214. ----+----+----+-----+-----+-----
  215. 1 | 11 | 1 | 111 | 1 | 11
  216. 2 | 22 | 2 | 222 | 2 | 22
  217. 4 | 44 | 4 | | 4 | 44
  218. (3 rows)
  219. --
  220. -- regression test: check for bug with propagation of implied equality
  221. -- to outside an IN
  222. --
  223. select count(*) from tenk1 a where unique1 in
  224. (select unique1 from tenk1 b join tenk1 c using (unique1)
  225. where b.unique2 = 42);
  226. count
  227. -------
  228. 1
  229. (1 row)
  230. -- try that with GEQO too
  231. begin;
  232. rollback;
  233. --
  234. -- regression test: check a case where join_clause_is_movable_into() gives
  235. -- an imprecise result, causing an assertion failure
  236. --
  237. select count(*)
  238. from
  239. (select t3.tenthous as x1, coalesce(t1.stringu1, t2.stringu1) as x2
  240. from tenk1 t1
  241. left join tenk1 t2 on t1.unique1 = t2.unique1
  242. join tenk1 t3 on t1.unique2 = t3.unique2) ss,
  243. tenk1 t4,
  244. tenk1 t5
  245. where t4.thousand = t5.unique1 and ss.x1 = t4.tenthous and ss.x2 = t5.stringu1;
  246. count
  247. -------
  248. 1000
  249. (1 row)
  250. select count(*) from
  251. (select * from tenk1 x order by x.thousand, x.twothousand, x.fivethous) x
  252. left join
  253. (select * from tenk1 y order by y.unique2) y
  254. on x.thousand = y.unique2 and x.twothousand = y.hundred and x.fivethous = y.unique2;
  255. count
  256. -------
  257. 10000
  258. (1 row)
  259. --
  260. -- Clean up
  261. --
  262. DROP TABLE t1;
  263. DROP TABLE t2;
  264. DROP TABLE t3;
  265. DROP TABLE J1_TBL;
  266. DROP TABLE J2_TBL;
  267. -- Both DELETE and UPDATE allow the specification of additional tables
  268. -- to "join" against to determine which rows should be modified.
  269. CREATE TEMP TABLE t1 (a int, b int);
  270. CREATE TEMP TABLE t2 (a int, b int);
  271. CREATE TEMP TABLE t3 (x int, y int);
  272. INSERT INTO t1 VALUES (5, 10);
  273. INSERT INTO t1 VALUES (15, 20);
  274. INSERT INTO t1 VALUES (100, 100);
  275. INSERT INTO t1 VALUES (200, 1000);
  276. INSERT INTO t2 VALUES (200, 2000);
  277. INSERT INTO t3 VALUES (5, 20);
  278. INSERT INTO t3 VALUES (6, 7);
  279. INSERT INTO t3 VALUES (7, 8);
  280. INSERT INTO t3 VALUES (500, 100);
  281. --
  282. -- regression test for 8.1 merge right join bug
  283. --
  284. CREATE TEMP TABLE tt1 ( tt1_id int4, joincol int4 );
  285. INSERT INTO tt1 VALUES (1, 11);
  286. INSERT INTO tt1 VALUES (2, NULL);
  287. CREATE TEMP TABLE tt2 ( tt2_id int4, joincol int4 );
  288. INSERT INTO tt2 VALUES (21, 11);
  289. INSERT INTO tt2 VALUES (22, 11);
  290. select count(*) from tenk1 a, tenk1 b
  291. where a.hundred = b.thousand and (b.fivethous % 10) < 10;
  292. count
  293. --------
  294. 100000
  295. (1 row)
  296. --
  297. -- regression test for 8.2 bug with improper re-ordering of left joins
  298. --
  299. create temp table tt3(f1 int, f2 text);
  300. insert into tt3 select x, repeat('xyzzy', 100) from generate_series(1,10000) x;
  301. create index tt3i on tt3(f1);
  302. create temp table tt4(f1 int);
  303. insert into tt4 values (0),(1),(9999);
  304. --
  305. -- regression test for proper handling of outer joins within antijoins
  306. --
  307. create temp table tt4x(c1 int, c2 int, c3 int);
  308. --
  309. -- regression test for problems of the sort depicted in bug #3494
  310. --
  311. create temp table tt5(f1 int, f2 int);
  312. create temp table tt6(f1 int, f2 int);
  313. insert into tt5 values(1, 10);
  314. insert into tt5 values(1, 11);
  315. insert into tt6 values(1, 9);
  316. insert into tt6 values(1, 2);
  317. insert into tt6 values(2, 9);
  318. --
  319. -- regression test for problems of the sort depicted in bug #3588
  320. --
  321. create temp table xx (pkxx int);
  322. create temp table yy (pkyy int, pkxx int);
  323. insert into xx values (1);
  324. insert into xx values (2);
  325. insert into xx values (3);
  326. insert into yy values (101, 1);
  327. insert into yy values (201, 2);
  328. insert into yy values (301, NULL);
  329. --
  330. -- regression test for improper pushing of constants across outer-join clauses
  331. -- (as seen in early 8.2.x releases)
  332. --
  333. create temp table zt1 (f1 int primary key);
  334. create temp table zt2 (f2 int primary key);
  335. create temp table zt3 (f3 int primary key);
  336. insert into zt1 values(53);
  337. insert into zt2 values(53);
  338. select * from
  339. zt2 left join zt3 on (f2 = f3)
  340. left join zt1 on (f3 = f1)
  341. where f2 = 53;
  342. f2 | f3 | f1
  343. ----+----+----
  344. 53 | |
  345. (1 row)
  346. --
  347. -- test for sane behavior with noncanonical merge clauses, per bug #4926
  348. --
  349. begin;
  350. create temp table a (i integer);
  351. create temp table b (x integer, y integer);
  352. select * from a left join b on i = x and i = y and x = i;
  353. i | x | y
  354. ---+---+---
  355. (0 rows)
  356. rollback;
  357. --
  358. -- test handling of merge clauses using record_ops
  359. --
  360. begin;
  361. create temp table tidv (idv mycomptype);
  362. create index on tidv (idv);
  363. rollback;
  364. --
  365. -- test incorrect failure to NULL pulled-up subexpressions
  366. --
  367. begin;
  368. create temp table a (
  369. code char not null,
  370. constraint a_pk primary key (code)
  371. );
  372. create temp table b (
  373. a char not null,
  374. num integer not null,
  375. constraint b_pk primary key (a, num)
  376. );
  377. create temp table c (
  378. name char not null,
  379. a char,
  380. constraint c_pk primary key (name)
  381. );
  382. insert into a (code) values ('p');
  383. insert into a (code) values ('q');
  384. insert into b (a, num) values ('p', 1);
  385. insert into b (a, num) values ('p', 2);
  386. insert into c (name, a) values ('A', 'p');
  387. insert into c (name, a) values ('B', 'q');
  388. insert into c (name, a) values ('C', null);
  389. rollback;
  390. --
  391. -- test incorrect handling of placeholders that only appear in targetlists,
  392. -- per bug #6154
  393. --
  394. SELECT * FROM
  395. ( SELECT 1 as key1 ) sub1
  396. LEFT JOIN
  397. ( SELECT sub3.key3, sub4.value2, COALESCE(sub4.value2, 66) as value3 FROM
  398. ( SELECT 1 as key3 ) sub3
  399. LEFT JOIN
  400. ( SELECT sub5.key5, COALESCE(sub6.value1, 1) as value2 FROM
  401. ( SELECT 1 as key5 ) sub5
  402. LEFT JOIN
  403. ( SELECT 2 as key6, 42 as value1 ) sub6
  404. ON sub5.key5 = sub6.key6
  405. ) sub4
  406. ON sub4.key5 = sub3.key3
  407. ) sub2
  408. ON sub1.key1 = sub2.key3;
  409. key1 | key3 | value2 | value3
  410. ------+------+--------+--------
  411. 1 | 1 | 1 | 1
  412. (1 row)
  413. -- test the path using join aliases, too
  414. SELECT * FROM
  415. ( SELECT 1 as key1 ) sub1
  416. LEFT JOIN
  417. ( SELECT sub3.key3, value2, COALESCE(value2, 66) as value3 FROM
  418. ( SELECT 1 as key3 ) sub3
  419. LEFT JOIN
  420. ( SELECT sub5.key5, COALESCE(sub6.value1, 1) as value2 FROM
  421. ( SELECT 1 as key5 ) sub5
  422. LEFT JOIN
  423. ( SELECT 2 as key6, 42 as value1 ) sub6
  424. ON sub5.key5 = sub6.key6
  425. ) sub4
  426. ON sub4.key5 = sub3.key3
  427. ) sub2
  428. ON sub1.key1 = sub2.key3;
  429. key1 | key3 | value2 | value3
  430. ------+------+--------+--------
  431. 1 | 1 | 1 | 1
  432. (1 row)
  433. --
  434. -- nested nestloops can require nested PlaceHolderVars
  435. --
  436. create temp table nt1 (
  437. id int primary key,
  438. a1 boolean,
  439. a2 boolean
  440. );
  441. insert into nt1 values (1,true,true);
  442. insert into nt1 values (2,true,false);
  443. insert into nt1 values (3,false,false);
  444. select * from
  445. int8_tbl t1 left join
  446. (select q1 as x, 42 as y from int8_tbl t2) ss
  447. on t1.q2 = ss.x
  448. where
  449. 1 = (select 1 from int8_tbl t3 where ss.y is not null limit 1)
  450. order by 1,2;
  451. q1 | q2 | x | y
  452. ------------------+------------------+------------------+----
  453. 123 | 4567890123456789 | 4567890123456789 | 42
  454. 123 | 4567890123456789 | 4567890123456789 | 42
  455. 123 | 4567890123456789 | 4567890123456789 | 42
  456. 4567890123456789 | 123 | 123 | 42
  457. 4567890123456789 | 123 | 123 | 42
  458. 4567890123456789 | 4567890123456789 | 4567890123456789 | 42
  459. 4567890123456789 | 4567890123456789 | 4567890123456789 | 42
  460. 4567890123456789 | 4567890123456789 | 4567890123456789 | 42
  461. (8 rows)
  462. select t1.unique2, t1.stringu1, t2.unique1, t2.stringu2 from
  463. tenk1 t1
  464. inner join int4_tbl i1
  465. left join (select v1.x2, v2.y1, 11 AS d1
  466. from (values(1,0)) v1(x1,x2)
  467. left join (values(3,1)) v2(y1,y2)
  468. on v1.x1 = v2.y2) subq1
  469. on (i1.f1 = subq1.x2)
  470. on (t1.unique2 = subq1.d1)
  471. left join tenk1 t2
  472. on (subq1.y1 = t2.unique1)
  473. where t1.unique2 < 42 and t1.stringu1 > t2.stringu2;
  474. unique2 | stringu1 | unique1 | stringu2
  475. ---------+----------+---------+----------
  476. 11 | WFAAAA | 3 | LKIAAA
  477. (1 row)
  478. select count(*) from
  479. tenk1 a join tenk1 b on a.unique1 = b.unique2
  480. left join tenk1 c on a.unique2 = b.unique1 and c.thousand = a.thousand
  481. join int4_tbl on b.thousand = f1;
  482. count
  483. -------
  484. 10
  485. (1 row)
  486. select f1, unique2, case when unique2 is null then f1 else 0 end
  487. from int4_tbl a left join tenk1 b on f1 = unique2
  488. where (case when unique2 is null then f1 else 0 end) = 0;
  489. f1 | unique2 | case
  490. ----+---------+------
  491. 0 | 0 | 0
  492. (1 row)
  493. --
  494. -- test join removal
  495. --
  496. begin;
  497. CREATE TEMP TABLE a (id int PRIMARY KEY, b_id int);
  498. CREATE TEMP TABLE b (id int PRIMARY KEY, c_id int);
  499. CREATE TEMP TABLE c (id int PRIMARY KEY);
  500. CREATE TEMP TABLE d (a int, b int);
  501. INSERT INTO b VALUES (0, 0), (1, NULL);
  502. INSERT INTO c VALUES (0), (1);
  503. INSERT INTO d VALUES (1,3), (2,2), (3,1);
  504. rollback;
  505. create temp table parent (k int primary key, pd int);
  506. create temp table child (k int unique, cd int);
  507. insert into parent values (1, 10), (2, 20), (3, 30);
  508. insert into child values (1, 100), (4, 400);
  509. -- check for a 9.0rc1 bug: join removal breaks pseudoconstant qual handling
  510. select p.* from
  511. parent p left join child c on (p.k = c.k)
  512. where p.k = 1 and p.k = 2;
  513. k | pd
  514. ---+----
  515. (0 rows)
  516. select p.* from
  517. (parent p left join child c on (p.k = c.k)) join parent x on p.k = x.k
  518. where p.k = 1 and p.k = 2;
  519. k | pd
  520. ---+----
  521. (0 rows)
  522. -- bug 5255: this is not optimizable by join removal
  523. begin;
  524. CREATE TEMP TABLE a (id int PRIMARY KEY);
  525. CREATE TEMP TABLE b (id int PRIMARY KEY, a_id int);
  526. INSERT INTO a VALUES (0), (1);
  527. INSERT INTO b VALUES (0, 0), (1, NULL);
  528. rollback;
  529. -- another join removal bug: this is not optimizable, either
  530. begin;
  531. create temp table innertab (id int8 primary key, dat1 int8);
  532. insert into innertab values(123, 42);
  533. rollback;
  534. -- another join removal bug: we must clean up correctly when removing a PHV
  535. begin;
  536. create temp table uniquetbl (f1 text unique);
  537. rollback;
  538. create table join_ut1 (a int, b int, c varchar);
  539. insert into join_ut1 values (101, 101, 'y'), (2, 2, 'z');
  540. drop table join_ut1;
  541. --
  542. -- test estimation behavior with multi-column foreign key and constant qual
  543. --
  544. begin;
  545. create table fkest (x integer, x10 integer, x10b integer, x100 integer);
  546. insert into fkest select x, x/10, x/10, x/100 from generate_series(1,1000) x;
  547. rollback;
  548. --
  549. -- test that foreign key join estimation performs sanely for outer joins
  550. --
  551. begin;
  552. create table fkest (a int, b int, c int unique, primary key(a,b));
  553. create table fkest1 (a int, b int, primary key(a,b));
  554. insert into fkest select x/10, x%10, x from generate_series(1,1000) x;
  555. insert into fkest1 select x/10, x%10 from generate_series(1,1000) x;
  556. rollback;
  557. --
  558. -- test planner's ability to mark joins as unique
  559. --
  560. create table j1 (id int primary key);
  561. create table j2 (id int primary key);
  562. create table j3 (id int);
  563. insert into j1 values(1),(2),(3);
  564. insert into j2 values(1),(2),(3);
  565. insert into j3 values(1),(1);
  566. drop table j1;
  567. drop table j2;
  568. drop table j3;
  569. -- test more complex permutations of unique joins
  570. create table j1 (id1 int, id2 int, primary key(id1,id2));
  571. create table j2 (id1 int, id2 int, primary key(id1,id2));
  572. create table j3 (id1 int, id2 int, primary key(id1,id2));
  573. insert into j1 values(1,1),(1,2);
  574. insert into j2 values(1,1);
  575. insert into j3 values(1,1);
  576. -- need an additional row in j2, if we want j2_id1_idx to be preferred
  577. insert into j2 values(1,2);
  578. drop table j1;
  579. drop table j2;
  580. drop table j3;