0000: 23 20 32 30 30 35 20 53 65 70 74 65 6d 62 65 72 # 2005 September
0010: 20 31 37 0a 23 0a 23 20 54 68 65 20 61 75 74 68 17.#.# The auth
0020: 6f 72 20 64 69 73 63 6c 61 69 6d 73 20 63 6f 70 or disclaims cop
0030: 79 72 69 67 68 74 20 74 6f 20 74 68 69 73 20 73 yright to this s
0040: 6f 75 72 63 65 20 63 6f 64 65 2e 20 20 49 6e 20 ource code. In
0050: 70 6c 61 63 65 20 6f 66 0a 23 20 61 20 6c 65 67 place of.# a leg
0060: 61 6c 20 6e 6f 74 69 63 65 2c 20 68 65 72 65 20 al notice, here
0070: 69 73 20 61 20 62 6c 65 73 73 69 6e 67 3a 0a 23 is a blessing:.#
0080: 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20 64 6f .# May you do
0090: 20 67 6f 6f 64 20 61 6e 64 20 6e 6f 74 20 65 76 good and not ev
00a0: 69 6c 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 il..# May you
00b0: 20 66 69 6e 64 20 66 6f 72 67 69 76 65 6e 65 73 find forgivenes
00c0: 73 20 66 6f 72 20 79 6f 75 72 73 65 6c 66 20 61 s for yourself a
00d0: 6e 64 20 66 6f 72 67 69 76 65 20 6f 74 68 65 72 nd forgive other
00e0: 73 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20 s..# May you
00f0: 73 68 61 72 65 20 66 72 65 65 6c 79 2c 20 6e 65 share freely, ne
0100: 76 65 72 20 74 61 6b 69 6e 67 20 6d 6f 72 65 20 ver taking more
0110: 74 68 61 6e 20 79 6f 75 20 67 69 76 65 2e 0a 23 than you give..#
0120: 0a 23 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a .#**************
0130: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0140: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0150: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a ****************
0160: 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a 23 20 54 68 69 73 *********.# This
0170: 20 66 69 6c 65 20 69 6d 70 6c 65 6d 65 6e 74 73 file implements
0180: 20 72 65 67 72 65 73 73 69 6f 6e 20 74 65 73 74 regression test
0190: 73 20 66 6f 72 20 53 51 4c 69 74 65 20 6c 69 62 s for SQLite lib
01a0: 72 61 72 79 2e 0a 23 0a 23 20 54 68 69 73 20 66 rary..#.# This f
01b0: 69 6c 65 20 69 6d 70 6c 65 6d 65 6e 74 73 20 74 ile implements t
01c0: 65 73 74 73 20 74 6f 20 76 65 72 69 66 79 20 74 ests to verify t
01d0: 68 61 74 20 74 69 63 6b 65 74 20 23 31 34 33 33 hat ticket #1433
01e0: 20 68 61 73 20 62 65 65 6e 0a 23 20 66 69 78 65 has been.# fixe
01f0: 64 2e 20 20 0a 23 0a 23 20 54 68 65 20 70 72 6f d. .#.# The pro
0200: 62 6c 65 6d 20 69 6e 20 74 69 63 6b 65 74 20 23 blem in ticket #
0210: 31 34 33 33 20 77 61 73 20 74 68 61 74 20 74 68 1433 was that th
0220: 65 20 64 65 70 65 6e 64 65 6e 63 69 65 73 20 6f e dependencies o
0230: 6e 20 74 68 65 20 72 69 67 68 74 2d 68 61 6e 64 n the right-hand
0240: 0a 23 20 73 69 64 65 20 6f 66 20 61 6e 20 49 4e .# side of an IN
0250: 20 6f 70 65 72 61 74 6f 72 20 77 65 72 65 20 6e operator were n
0260: 6f 74 20 62 65 69 6e 67 20 63 68 65 63 6b 65 64 ot being checked
0270: 20 63 6f 72 72 65 63 74 6c 79 2e 20 20 53 6f 20 correctly. So
0280: 69 6e 20 61 6e 0a 23 20 65 78 70 72 65 73 73 69 in an.# expressi
0290: 6f 6e 20 6f 66 20 74 68 65 20 66 6f 72 6d 3a 0a on of the form:.
02a0: 23 0a 23 20 20 20 20 20 20 20 20 20 74 31 2e 78 #.# t1.x
02b0: 20 49 4e 20 28 31 2c 74 32 2e 62 2c 33 29 0a 23 IN (1,t2.b,3).#
02c0: 0a 23 20 74 68 65 20 6f 70 74 69 6d 69 7a 65 72 .# the optimizer
02d0: 20 77 61 73 20 6d 69 73 73 69 6e 67 20 74 68 65 was missing the
02e0: 20 66 61 63 74 20 74 68 61 74 20 74 68 65 20 72 fact that the r
02f0: 69 67 68 74 2d 68 61 6e 64 20 73 69 64 65 20 6f ight-hand side o
0300: 66 20 74 68 65 20 49 4e 0a 23 20 64 65 70 65 6e f the IN.# depen
0310: 64 65 64 20 6f 6e 20 74 61 62 6c 65 20 74 32 2e ded on table t2.
0320: 20 20 49 74 20 77 61 73 20 63 68 65 63 6b 69 6e It was checkin
0330: 67 20 64 65 70 65 6e 64 65 6e 63 69 65 73 20 62 g dependencies b
0340: 61 73 65 64 20 6f 6e 20 74 68 65 0a 23 20 45 78 ased on the.# Ex
0350: 70 72 2e 70 52 69 67 68 74 20 66 69 65 6c 64 20 pr.pRight field
0360: 72 61 74 68 65 72 20 74 68 61 6e 20 45 78 70 72 rather than Expr
0370: 2e 70 4c 69 73 74 20 61 6e 64 20 45 78 70 72 2e .pList and Expr.
0380: 70 53 65 6c 65 63 74 2e 20 20 0a 23 0a 23 20 53 pSelect. .#.# S
0390: 75 63 68 20 61 20 62 75 67 20 63 6f 75 6c 64 20 uch a bug could
03a0: 62 65 20 76 65 72 69 66 65 64 20 75 73 69 6e 67 be verifed using
03b0: 20 61 20 6c 65 73 73 20 65 6c 61 62 6f 72 61 74 a less elaborat
03c0: 65 20 74 65 73 74 20 63 61 73 65 2e 20 20 42 75 e test case. Bu
03d0: 74 0a 23 20 74 68 69 73 20 74 65 73 74 20 63 61 t.# this test ca
03e0: 73 65 20 28 66 72 6f 6d 20 74 68 65 20 6f 72 69 se (from the ori
03f0: 67 69 6e 61 6c 20 62 75 67 20 70 6f 73 74 65 72 ginal bug poster
0400: 29 20 65 78 65 72 63 69 73 65 73 20 73 6f 20 6d ) exercises so m
0410: 61 6e 79 20 64 69 66 66 65 72 65 6e 74 0a 23 20 any different.#
0420: 70 61 72 74 73 20 6f 66 20 74 68 65 20 73 79 73 parts of the sys
0430: 74 65 6d 20 61 6c 6c 20 61 74 20 6f 6e 63 65 2c tem all at once,
0440: 20 74 68 61 74 20 69 74 20 73 65 65 6d 65 64 20 that it seemed
0450: 6c 69 6b 65 20 61 20 67 6f 6f 64 20 6f 6e 65 20 like a good one
0460: 74 6f 0a 23 20 69 6e 63 6c 75 64 65 20 69 6e 20 to.# include in
0470: 74 68 65 20 74 65 73 74 20 73 75 69 74 65 2e 20 the test suite.
0480: 0a 23 0a 23 20 4e 4f 54 45 3a 20 20 59 65 73 2c .#.# NOTE: Yes,
0490: 20 69 6e 20 73 70 69 74 65 20 6f 66 20 74 68 65 in spite of the
04a0: 20 6e 61 6d 65 20 6f 66 20 74 68 69 73 20 66 69 name of this fi
04b0: 6c 65 20 28 74 6b 74 31 34 34 33 2e 74 65 73 74 le (tkt1443.test
04c0: 29 20 74 68 69 73 0a 23 20 74 65 73 74 20 69 73 ) this.# test is
04d0: 20 66 6f 72 20 74 69 63 6b 65 74 20 23 31 34 33 for ticket #143
04e0: 33 20 6e 6f 74 20 23 31 34 34 33 2e 20 20 49 20 3 not #1443. I
04f0: 6d 69 73 74 79 70 65 64 20 74 68 65 20 6e 61 6d mistyped the nam
0500: 65 20 77 68 65 6e 20 49 20 77 61 73 0a 23 20 63 e when I was.# c
0510: 72 65 61 74 69 6e 67 20 74 68 65 20 66 69 6c 65 reating the file
0520: 20 61 6e 64 20 49 20 68 61 64 20 61 6c 72 65 61 and I had alrea
0530: 64 79 20 63 68 65 63 6b 65 64 20 69 6e 20 74 68 dy checked in th
0540: 65 20 66 69 6c 65 20 62 79 20 74 68 65 20 77 72 e file by the wr
0550: 6f 6e 67 0a 23 20 6e 61 6d 65 20 62 65 20 74 68 ong.# name be th
0560: 65 20 74 69 6d 65 20 49 20 6e 6f 74 69 63 65 64 e time I noticed
0570: 20 74 68 65 20 65 72 72 6f 72 2e 20 20 57 69 74 the error. Wit
0580: 68 20 43 56 53 20 69 74 20 69 73 20 61 20 72 65 h CVS it is a re
0590: 61 6c 6c 79 20 68 61 73 73 6c 65 0a 23 20 74 6f ally hassle.# to
05a0: 20 63 68 61 6e 67 65 20 66 69 6c 65 6e 61 6d 65 change filename
05b0: 73 2c 20 73 6f 20 49 27 6c 6c 20 6a 75 73 74 20 s, so I'll just
05c0: 6c 65 61 76 65 20 69 74 20 61 73 20 69 73 2e 20 leave it as is.
05d0: 20 4e 6f 20 68 61 72 6d 20 64 6f 6e 65 2e 0a 23 No harm done..#
05e0: 0a 23 20 24 49 64 3a 20 74 6b 74 31 34 34 33 2e .# $Id: tkt1443.
05f0: 74 65 73 74 2c 76 20 31 2e 34 20 32 30 30 36 2f test,v 1.4 2006/
0600: 30 31 2f 31 37 20 30 39 3a 33 35 3a 30 32 20 64 01/17 09:35:02 d
0610: 61 6e 69 65 6c 6b 31 39 37 37 20 45 78 70 20 24 anielk1977 Exp $
0620: 0a 0a 73 65 74 20 74 65 73 74 64 69 72 20 5b 66 ..set testdir [f
0630: 69 6c 65 20 64 69 72 6e 61 6d 65 20 24 61 72 67 ile dirname $arg
0640: 76 30 5d 0a 73 6f 75 72 63 65 20 24 74 65 73 74 v0].source $test
0650: 64 69 72 2f 74 65 73 74 65 72 2e 74 63 6c 0a 0a dir/tester.tcl..
0660: 69 66 63 61 70 61 62 6c 65 20 21 73 75 62 71 75 ifcapable !subqu
0670: 65 72 79 7c 7c 21 6d 65 6d 6f 72 79 64 62 20 7b ery||!memorydb {
0680: 0a 20 20 66 69 6e 69 73 68 5f 74 65 73 74 0a 20 . finish_test.
0690: 20 72 65 74 75 72 6e 0a 7d 0a 0a 23 20 43 6f 6e return.}..# Con
06a0: 73 74 72 75 63 74 20 74 68 65 20 73 61 6d 70 6c struct the sampl
06b0: 65 20 64 61 74 61 62 61 73 65 2e 0a 23 0a 64 6f e database..#.do
06c0: 5f 74 65 73 74 20 74 6b 74 31 34 34 33 2d 31 2e _test tkt1443-1.
06d0: 30 20 7b 0a 20 20 73 71 6c 69 74 65 33 20 64 62 0 {. sqlite3 db
06e0: 20 3a 6d 65 6d 6f 72 79 3a 0a 20 20 65 78 65 63 :memory:. exec
06f0: 73 71 6c 20 7b 0a 20 20 20 20 43 52 45 41 54 45 sql {. CREATE
0700: 20 54 41 42 4c 45 20 49 74 65 6d 73 28 0a 20 20 TABLE Items(.
0710: 20 20 09 69 74 65 6d 49 64 20 69 6e 74 65 67 65 .itemId intege
0720: 72 20 70 72 69 6d 61 72 79 20 6b 65 79 2c 0a 20 r primary key,.
0730: 20 20 20 09 20 69 74 65 6d 20 73 74 72 20 75 6e . item str un
0740: 69 71 75 65 0a 20 20 20 20 29 3b 0a 20 20 20 20 ique. );.
0750: 49 4e 53 45 52 54 20 49 4e 54 4f 20 22 49 74 65 INSERT INTO "Ite
0760: 6d 73 22 20 56 41 4c 55 45 53 28 30 2c 20 27 41 ms" VALUES(0, 'A
0770: 4c 4c 27 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 LL');. INSERT
0780: 20 49 4e 54 4f 20 22 49 74 65 6d 73 22 20 56 41 INTO "Items" VA
0790: 4c 55 45 53 28 31 2c 20 27 64 6f 75 62 6c 65 3a LUES(1, 'double:
07a0: 73 6f 75 72 63 65 27 29 3b 0a 20 20 20 20 49 4e source');. IN
07b0: 53 45 52 54 20 49 4e 54 4f 20 22 49 74 65 6d 73 SERT INTO "Items
07c0: 22 20 56 41 4c 55 45 53 28 32 2c 20 27 64 6f 75 " VALUES(2, 'dou
07d0: 62 6c 65 27 29 3b 0a 20 20 20 20 49 4e 53 45 52 ble');. INSER
07e0: 54 20 49 4e 54 4f 20 22 49 74 65 6d 73 22 20 56 T INTO "Items" V
07f0: 41 4c 55 45 53 28 33 2c 20 27 64 6f 75 62 6c 65 ALUES(3, 'double
0800: 3a 72 75 6e 74 69 6d 65 27 29 3b 0a 20 20 20 20 :runtime');.
0810: 49 4e 53 45 52 54 20 49 4e 54 4f 20 22 49 74 65 INSERT INTO "Ite
0820: 6d 73 22 20 56 41 4c 55 45 53 28 34 2c 20 27 2e ms" VALUES(4, '.
0830: 2a 3a 72 75 6e 74 69 6d 65 27 29 3b 0a 20 20 20 *:runtime');.
0840: 20 0a 20 20 20 20 43 52 45 41 54 45 20 54 41 42 . CREATE TAB
0850: 4c 45 20 4c 61 62 65 6c 73 28 0a 20 20 20 20 09 LE Labels(. .
0860: 6c 61 62 65 6c 49 64 20 49 4e 54 45 47 45 52 20 labelId INTEGER
0870: 50 52 49 4d 41 52 59 20 4b 45 59 2c 0a 20 20 20 PRIMARY KEY,.
0880: 20 09 6c 61 62 65 6c 20 53 54 52 20 55 4e 49 51 .label STR UNIQ
0890: 55 45 0a 20 20 20 20 29 3b 0a 20 20 20 20 49 4e UE. );. IN
08a0: 53 45 52 54 20 49 4e 54 4f 20 22 4c 61 62 65 6c SERT INTO "Label
08b0: 73 22 20 56 41 4c 55 45 53 28 30 2c 20 27 41 4c s" VALUES(0, 'AL
08c0: 4c 27 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 L');. INSERT
08d0: 49 4e 54 4f 20 22 4c 61 62 65 6c 73 22 20 56 41 INTO "Labels" VA
08e0: 4c 55 45 53 28 31 2c 20 27 6c 6f 63 61 6c 68 6f LUES(1, 'localho
08f0: 73 74 40 72 70 6c 3a 6c 69 6e 75 78 27 29 3b 0a st@rpl:linux');.
0900: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 INSERT INTO
0910: 22 4c 61 62 65 6c 73 22 20 56 41 4c 55 45 53 28 "Labels" VALUES(
0920: 32 2c 20 27 6c 6f 63 61 6c 68 6f 73 74 40 72 70 2, 'localhost@rp
0930: 6c 3a 62 72 61 6e 63 68 27 29 3b 0a 20 20 20 20 l:branch');.
0940: 0a 20 20 20 20 43 52 45 41 54 45 20 54 41 42 4c . CREATE TABL
0950: 45 20 4c 61 62 65 6c 4d 61 70 28 0a 20 20 20 20 E LabelMap(.
0960: 09 69 74 65 6d 49 64 20 49 4e 54 45 47 45 52 2c .itemId INTEGER,
0970: 0a 20 20 20 20 09 6c 61 62 65 6c 49 64 20 49 4e . .labelId IN
0980: 54 45 47 45 52 2c 0a 20 20 20 20 09 62 72 61 6e TEGER,. .bran
0990: 63 68 49 64 20 69 6e 74 65 67 65 72 0a 20 20 20 chId integer.
09a0: 20 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 );. INSERT I
09b0: 4e 54 4f 20 22 4c 61 62 65 6c 4d 61 70 22 20 56 NTO "LabelMap" V
09c0: 41 4c 55 45 53 28 31 2c 20 31 2c 20 31 29 3b 0a ALUES(1, 1, 1);.
09d0: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 INSERT INTO
09e0: 22 4c 61 62 65 6c 4d 61 70 22 20 56 41 4c 55 45 "LabelMap" VALUE
09f0: 53 28 32 2c 20 31 2c 20 31 29 3b 0a 20 20 20 20 S(2, 1, 1);.
0a00: 49 4e 53 45 52 54 20 49 4e 54 4f 20 22 4c 61 62 INSERT INTO "Lab
0a10: 65 6c 4d 61 70 22 20 56 41 4c 55 45 53 28 33 2c elMap" VALUES(3,
0a20: 20 31 2c 20 31 29 3b 0a 20 20 20 20 49 4e 53 45 1, 1);. INSE
0a30: 52 54 20 49 4e 54 4f 20 22 4c 61 62 65 6c 4d 61 RT INTO "LabelMa
0a40: 70 22 20 56 41 4c 55 45 53 28 31 2c 20 32 2c 20 p" VALUES(1, 2,
0a50: 32 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 2);. INSERT I
0a60: 4e 54 4f 20 22 4c 61 62 65 6c 4d 61 70 22 20 56 NTO "LabelMap" V
0a70: 41 4c 55 45 53 28 32 2c 20 32 2c 20 33 29 3b 0a ALUES(2, 2, 3);.
0a80: 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 INSERT INTO
0a90: 22 4c 61 62 65 6c 4d 61 70 22 20 56 41 4c 55 45 "LabelMap" VALUE
0aa0: 53 28 33 2c 20 32 2c 20 33 29 3b 0a 20 20 20 20 S(3, 2, 3);.
0ab0: 0a 20 20 20 20 43 52 45 41 54 45 20 54 41 42 4c . CREATE TABL
0ac0: 45 20 55 73 65 72 73 20 28 0a 20 20 20 20 09 75 E Users (. .u
0ad0: 73 65 72 49 64 20 49 4e 54 45 47 45 52 20 50 52 serId INTEGER PR
0ae0: 49 4d 41 52 59 20 4b 45 59 2c 0a 20 20 20 20 09 IMARY KEY,. .
0af0: 75 73 65 72 20 53 54 52 49 4e 47 20 55 4e 49 51 user STRING UNIQ
0b00: 55 45 2c 0a 20 20 20 20 09 73 61 6c 74 20 42 49 UE,. .salt BI
0b10: 4e 41 52 59 2c 0a 20 20 20 20 09 70 61 73 73 77 NARY,. .passw
0b20: 6f 72 64 20 53 54 52 49 4e 47 0a 20 20 20 20 29 ord STRING. )
0b30: 3b 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 ;. INSERT INT
0b40: 4f 20 22 55 73 65 72 73 22 20 56 41 4c 55 45 53 O "Users" VALUES
0b50: 28 31 2c 20 27 74 65 73 74 27 2c 20 27 c2 8a c3 (1, 'test', '...
0b60: a6 24 64 27 2c 0a 20 20 20 20 20 20 20 20 20 20 .$d',.
0b70: 20 20 20 20 20 27 34 33 62 61 30 66 34 35 30 31 '43ba0f4501
0b80: 34 33 30 36 62 64 36 64 66 35 32 39 35 35 31 66 4306bd6df529551f
0b90: 66 64 62 33 64 66 27 29 3b 0a 20 20 20 20 49 4e fdb3df');. IN
0ba0: 53 45 52 54 20 49 4e 54 4f 20 22 55 73 65 72 73 SERT INTO "Users
0bb0: 22 20 56 41 4c 55 45 53 28 32 2c 20 27 6c 69 6d " VALUES(2, 'lim
0bc0: 69 74 65 64 27 2c 20 27 c2 aa c2 9a 3e 53 27 2c ited', '....>S',
0bd0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 .
0be0: 27 63 66 30 37 63 38 33 34 38 66 64 66 36 37 35 'cf07c8348fdf675
0bf0: 63 63 31 66 37 36 39 36 62 37 64 34 35 31 39 31 cc1f7696b7d45191
0c00: 62 27 29 3b 0a 20 20 20 20 43 52 45 41 54 45 20 b');. CREATE
0c10: 54 41 42 4c 45 20 55 73 65 72 47 72 6f 75 70 73 TABLE UserGroups
0c20: 20 28 0a 20 20 20 20 09 75 73 65 72 47 72 6f 75 (. .userGrou
0c30: 70 49 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d pId INTEGER PRIM
0c40: 41 52 59 20 4b 45 59 2c 0a 20 20 20 20 09 75 73 ARY KEY,. .us
0c50: 65 72 47 72 6f 75 70 20 53 54 52 49 4e 47 20 55 erGroup STRING U
0c60: 4e 49 51 55 45 0a 20 20 20 20 29 3b 0a 20 20 20 NIQUE. );.
0c70: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 22 55 73 INSERT INTO "Us
0c80: 65 72 47 72 6f 75 70 73 22 20 56 41 4c 55 45 53 erGroups" VALUES
0c90: 28 31 2c 20 27 74 65 73 74 27 29 3b 0a 20 20 20 (1, 'test');.
0ca0: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 22 55 73 INSERT INTO "Us
0cb0: 65 72 47 72 6f 75 70 73 22 20 56 41 4c 55 45 53 erGroups" VALUES
0cc0: 28 32 2c 20 27 6c 69 6d 69 74 65 64 27 29 3b 0a (2, 'limited');.
0cd0: 20 20 20 20 0a 20 20 20 20 43 52 45 41 54 45 20 . CREATE
0ce0: 54 41 42 4c 45 20 55 73 65 72 47 72 6f 75 70 4d TABLE UserGroupM
0cf0: 65 6d 62 65 72 73 20 28 0a 20 20 20 20 09 75 73 embers (. .us
0d00: 65 72 47 72 6f 75 70 49 64 20 49 4e 54 45 47 45 erGroupId INTEGE
0d10: 52 2c 0a 20 20 20 20 09 75 73 65 72 49 64 20 49 R,. .userId I
0d20: 4e 54 45 47 45 52 0a 20 20 20 20 29 3b 0a 20 20 NTEGER. );.
0d30: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 22 55 INSERT INTO "U
0d40: 73 65 72 47 72 6f 75 70 4d 65 6d 62 65 72 73 22 serGroupMembers"
0d50: 20 56 41 4c 55 45 53 28 31 2c 20 31 29 3b 0a 20 VALUES(1, 1);.
0d60: 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 22 INSERT INTO "
0d70: 55 73 65 72 47 72 6f 75 70 4d 65 6d 62 65 72 73 UserGroupMembers
0d80: 22 20 56 41 4c 55 45 53 28 32 2c 20 32 29 3b 0a " VALUES(2, 2);.
0d90: 20 20 20 20 0a 20 20 20 20 43 52 45 41 54 45 20 . CREATE
0da0: 54 41 42 4c 45 20 50 65 72 6d 69 73 73 69 6f 6e TABLE Permission
0db0: 73 20 28 0a 20 20 20 20 09 75 73 65 72 47 72 6f s (. .userGro
0dc0: 75 70 49 64 20 49 4e 54 45 47 45 52 2c 0a 20 20 upId INTEGER,.
0dd0: 20 20 09 6c 61 62 65 6c 49 64 20 49 4e 54 45 47 .labelId INTEG
0de0: 45 52 20 4e 4f 54 20 4e 55 4c 4c 2c 0a 20 20 20 ER NOT NULL,.
0df0: 20 09 69 74 65 6d 49 64 20 49 4e 54 45 47 45 52 .itemId INTEGER
0e00: 20 4e 4f 54 20 4e 55 4c 4c 2c 0a 20 20 20 20 09 NOT NULL,. .
0e10: 77 72 69 74 65 20 49 4e 54 45 47 45 52 2c 0a 20 write INTEGER,.
0e20: 20 20 20 09 63 61 70 70 65 64 20 49 4e 54 45 47 .capped INTEG
0e30: 45 52 2c 0a 20 20 20 20 09 61 64 6d 69 6e 20 49 ER,. .admin I
0e40: 4e 54 45 47 45 52 0a 20 20 20 20 29 3b 0a 20 20 NTEGER. );.
0e50: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 22 50 INSERT INTO "P
0e60: 65 72 6d 69 73 73 69 6f 6e 73 22 20 56 41 4c 55 ermissions" VALU
0e70: 45 53 28 31 2c 20 30 2c 20 30 2c 20 31 2c 20 30 ES(1, 0, 0, 1, 0
0e80: 2c 20 31 29 3b 0a 20 20 20 20 49 4e 53 45 52 54 , 1);. INSERT
0e90: 20 49 4e 54 4f 20 22 50 65 72 6d 69 73 73 69 6f INTO "Permissio
0ea0: 6e 73 22 20 56 41 4c 55 45 53 28 32 2c 20 32 2c ns" VALUES(2, 2,
0eb0: 20 34 2c 20 30 2c 20 30 2c 20 30 29 3b 0a 20 20 4, 0, 0, 0);.
0ec0: 7d 0a 7d 20 7b 7d 0a 0a 23 20 52 75 6e 20 74 68 }.} {}..# Run th
0ed0: 65 20 71 75 65 72 79 20 77 69 74 68 20 61 6e 20 e query with an
0ee0: 69 6e 64 65 78 0a 23 0a 64 6f 5f 74 65 73 74 20 index.#.do_test
0ef0: 74 6b 74 31 34 34 33 2d 31 2e 31 20 7b 0a 20 20 tkt1443-1.1 {.
0f00: 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 73 65 execsql {. se
0f10: 6c 65 63 74 20 64 69 73 74 69 6e 63 74 0a 20 20 lect distinct.
0f20: 20 20 20 20 20 20 49 74 65 6d 73 2e 49 74 65 6d Items.Item
0f30: 20 61 73 20 74 72 6f 76 65 2c 20 55 50 2e 70 61 as trove, UP.pa
0f40: 74 74 65 72 6e 20 61 73 20 70 61 74 74 65 72 6e ttern as pattern
0f50: 0a 20 20 20 20 66 72 6f 6d 0a 20 20 20 20 20 20 . from.
0f60: 20 28 20 73 65 6c 65 63 74 0a 20 20 20 20 20 20 ( select.
0f70: 20 20 20 20 20 50 65 72 6d 69 73 73 69 6f 6e 73 Permissions
0f80: 2e 6c 61 62 65 6c 49 64 20 61 73 20 6c 61 62 65 .labelId as labe
0f90: 6c 49 64 2c 0a 20 20 20 20 20 20 20 20 20 20 20 lId,.
0fa0: 50 65 72 49 74 65 6d 73 2e 69 74 65 6d 20 61 73 PerItems.item as
0fb0: 20 70 61 74 74 65 72 6e 0a 20 20 20 20 20 20 20 pattern.
0fc0: 20 20 66 72 6f 6d 0a 20 20 20 20 20 20 20 20 20 from.
0fd0: 20 20 55 73 65 72 73 2c 20 55 73 65 72 47 72 6f Users, UserGro
0fe0: 75 70 4d 65 6d 62 65 72 73 2c 20 50 65 72 6d 69 upMembers, Permi
0ff0: 73 73 69 6f 6e 73 0a 20 20 20 20 20 20 20 20 20 ssions.
1000: 20 20 6c 65 66 74 20 6f 75 74 65 72 20 6a 6f 69 left outer joi
1010: 6e 20 49 74 65 6d 73 20 61 73 20 50 65 72 49 74 n Items as PerIt
1020: 65 6d 73 0a 20 20 20 20 20 20 20 20 20 20 20 20 ems.
1030: 20 20 20 20 20 6f 6e 20 50 65 72 6d 69 73 73 69 on Permissi
1040: 6f 6e 73 2e 69 74 65 6d 49 64 20 3d 20 50 65 72 ons.itemId = Per
1050: 49 74 65 6d 73 2e 69 74 65 6d 49 64 0a 20 20 20 Items.itemId.
1060: 20 20 20 20 20 20 77 68 65 72 65 0a 20 20 20 20 where.
1070: 20 20 20 20 20 20 20 20 20 20 20 55 73 65 72 73 Users
1080: 2e 75 73 65 72 20 3d 20 27 6c 69 6d 69 74 65 64 .user = 'limited
1090: 27 0a 20 20 20 20 20 20 20 20 20 20 20 61 6e 64 '. and
10a0: 20 55 73 65 72 73 2e 75 73 65 72 49 64 20 3d 20 Users.userId =
10b0: 55 73 65 72 47 72 6f 75 70 4d 65 6d 62 65 72 73 UserGroupMembers
10c0: 2e 75 73 65 72 49 64 0a 20 20 20 20 20 20 20 20 .userId.
10d0: 20 20 20 61 6e 64 20 55 73 65 72 47 72 6f 75 70 and UserGroup
10e0: 4d 65 6d 62 65 72 73 2e 75 73 65 72 47 72 6f 75 Members.userGrou
10f0: 70 49 64 20 3d 20 50 65 72 6d 69 73 73 69 6f 6e pId = Permission
1100: 73 2e 75 73 65 72 47 72 6f 75 70 49 64 0a 20 20 s.userGroupId.
1110: 20 20 20 20 20 29 20 61 73 20 55 50 20 6a 6f 69 ) as UP joi
1120: 6e 20 4c 61 62 65 6c 4d 61 70 20 6f 6e 20 28 20 n LabelMap on (
1130: 55 50 2e 6c 61 62 65 6c 49 64 20 3d 20 30 20 6f UP.labelId = 0 o
1140: 72 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 r.
1150: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
1160: 20 20 20 20 55 50 2e 6c 61 62 65 6c 49 64 20 3d UP.labelId =
1170: 20 4c 61 62 65 6c 4d 61 70 2e 6c 61 62 65 6c 49 LabelMap.labelI
1180: 64 20 29 2c 0a 20 20 20 20 20 20 20 4c 61 62 65 d ),. Labe
1190: 6c 73 2c 20 49 74 65 6d 73 0a 20 20 20 20 77 68 ls, Items. wh
11a0: 65 72 65 0a 20 20 20 20 20 20 20 20 4c 61 62 65 ere. Labe
11b0: 6c 73 2e 6c 61 62 65 6c 20 3d 20 27 6c 6f 63 61 ls.label = 'loca
11c0: 6c 68 6f 73 74 40 72 70 6c 3a 62 72 61 6e 63 68 lhost@rpl:branch
11d0: 27 0a 20 20 20 20 61 6e 64 20 4c 61 62 65 6c 73 '. and Labels
11e0: 2e 6c 61 62 65 6c 49 64 20 3d 20 4c 61 62 65 6c .labelId = Label
11f0: 4d 61 70 2e 6c 61 62 65 6c 49 64 0a 20 20 20 20 Map.labelId.
1200: 61 6e 64 20 4c 61 62 65 6c 4d 61 70 2e 69 74 65 and LabelMap.ite
1210: 6d 49 64 20 3d 20 49 74 65 6d 73 2e 69 74 65 6d mId = Items.item
1220: 49 64 0a 20 20 20 20 4f 52 44 45 52 20 42 59 20 Id. ORDER BY
1230: 2b 74 72 6f 76 65 2c 20 2b 70 61 74 74 65 72 6e +trove, +pattern
1240: 0a 20 20 7d 0a 7d 20 7b 64 6f 75 62 6c 65 20 2e . }.} {double .
1250: 2a 3a 72 75 6e 74 69 6d 65 20 64 6f 75 62 6c 65 *:runtime double
1260: 3a 72 75 6e 74 69 6d 65 20 2e 2a 3a 72 75 6e 74 :runtime .*:runt
1270: 69 6d 65 20 64 6f 75 62 6c 65 3a 73 6f 75 72 63 ime double:sourc
1280: 65 20 2e 2a 3a 72 75 6e 74 69 6d 65 7d 0a 0a 23 e .*:runtime}..#
1290: 20 43 72 65 61 74 65 20 61 6e 20 69 6e 64 65 78 Create an index
12a0: 20 61 6e 64 20 72 65 72 75 6e 20 74 68 65 20 71 and rerun the q
12b0: 75 65 72 79 2e 20 0a 23 20 56 65 72 69 66 79 20 uery. .# Verify
12c0: 74 68 61 74 20 74 68 65 20 72 65 73 75 6c 74 73 that the results
12d0: 20 61 72 65 20 74 68 65 20 73 61 6d 65 0a 23 0a are the same.#.
12e0: 64 6f 5f 74 65 73 74 20 74 6b 74 31 34 34 33 2d do_test tkt1443-
12f0: 31 2e 32 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 1.2 {. execsql
1300: 7b 0a 20 20 20 20 43 52 45 41 54 45 20 55 4e 49 {. CREATE UNI
1310: 51 55 45 20 49 4e 44 45 58 20 50 65 72 6d 69 73 QUE INDEX Permis
1320: 73 69 6f 6e 73 49 64 78 0a 20 20 20 20 20 20 20 sionsIdx.
1330: 20 20 4f 4e 20 50 65 72 6d 69 73 73 69 6f 6e 73 ON Permissions
1340: 28 75 73 65 72 47 72 6f 75 70 49 64 2c 20 6c 61 (userGroupId, la
1350: 62 65 6c 49 64 2c 20 69 74 65 6d 49 64 29 3b 0a belId, itemId);.
1360: 20 20 20 20 73 65 6c 65 63 74 20 64 69 73 74 69 select disti
1370: 6e 63 74 0a 20 20 20 20 20 20 20 20 49 74 65 6d nct. Item
1380: 73 2e 49 74 65 6d 20 61 73 20 74 72 6f 76 65 2c s.Item as trove,
1390: 20 55 50 2e 70 61 74 74 65 72 6e 20 61 73 20 70 UP.pattern as p
13a0: 61 74 74 65 72 6e 0a 20 20 20 20 66 72 6f 6d 0a attern. from.
13b0: 20 20 20 20 20 20 20 28 20 73 65 6c 65 63 74 0a ( select.
13c0: 20 20 20 20 20 20 20 20 20 20 20 50 65 72 6d 69 Permi
13d0: 73 73 69 6f 6e 73 2e 6c 61 62 65 6c 49 64 20 61 ssions.labelId a
13e0: 73 20 6c 61 62 65 6c 49 64 2c 0a 20 20 20 20 20 s labelId,.
13f0: 20 20 20 20 20 20 50 65 72 49 74 65 6d 73 2e 69 PerItems.i
1400: 74 65 6d 20 61 73 20 70 61 74 74 65 72 6e 0a 20 tem as pattern.
1410: 20 20 20 20 20 20 20 20 66 72 6f 6d 0a 20 20 20 from.
1420: 20 20 20 20 20 20 20 20 55 73 65 72 73 2c 20 55 Users, U
1430: 73 65 72 47 72 6f 75 70 4d 65 6d 62 65 72 73 2c serGroupMembers,
1440: 20 50 65 72 6d 69 73 73 69 6f 6e 73 0a 20 20 20 Permissions.
1450: 20 20 20 20 20 20 20 20 6c 65 66 74 20 6f 75 74 left out
1460: 65 72 20 6a 6f 69 6e 20 49 74 65 6d 73 20 61 73 er join Items as
1470: 20 50 65 72 49 74 65 6d 73 0a 20 20 20 20 20 20 PerItems.
1480: 20 20 20 20 20 20 20 20 20 20 20 6f 6e 20 50 65 on Pe
1490: 72 6d 69 73 73 69 6f 6e 73 2e 69 74 65 6d 49 64 rmissions.itemId
14a0: 20 3d 20 50 65 72 49 74 65 6d 73 2e 69 74 65 6d = PerItems.item
14b0: 49 64 0a 20 20 20 20 20 20 20 20 20 77 68 65 72 Id. wher
14c0: 65 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 e.
14d0: 20 55 73 65 72 73 2e 75 73 65 72 20 3d 20 27 6c Users.user = 'l
14e0: 69 6d 69 74 65 64 27 0a 20 20 20 20 20 20 20 20 imited'.
14f0: 20 20 20 61 6e 64 20 55 73 65 72 73 2e 75 73 65 and Users.use
1500: 72 49 64 20 3d 20 55 73 65 72 47 72 6f 75 70 4d rId = UserGroupM
1510: 65 6d 62 65 72 73 2e 75 73 65 72 49 64 0a 20 20 embers.userId.
1520: 20 20 20 20 20 20 20 20 20 61 6e 64 20 55 73 65 and Use
1530: 72 47 72 6f 75 70 4d 65 6d 62 65 72 73 2e 75 73 rGroupMembers.us
1540: 65 72 47 72 6f 75 70 49 64 20 3d 20 50 65 72 6d erGroupId = Perm
1550: 69 73 73 69 6f 6e 73 2e 75 73 65 72 47 72 6f 75 issions.userGrou
1560: 70 49 64 0a 20 20 20 20 20 20 20 29 20 61 73 20 pId. ) as
1570: 55 50 20 6a 6f 69 6e 20 4c 61 62 65 6c 4d 61 70 UP join LabelMap
1580: 20 6f 6e 20 28 20 55 50 2e 6c 61 62 65 6c 49 64 on ( UP.labelId
1590: 20 3d 20 30 20 6f 72 0a 20 20 20 20 20 20 20 20 = 0 or.
15a0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
15b0: 20 20 20 20 20 20 20 20 20 20 55 50 2e 6c 61 62 UP.lab
15c0: 65 6c 49 64 20 3d 20 4c 61 62 65 6c 4d 61 70 2e elId = LabelMap.
15d0: 6c 61 62 65 6c 49 64 20 29 2c 0a 20 20 20 20 20 labelId ),.
15e0: 20 20 4c 61 62 65 6c 73 2c 20 49 74 65 6d 73 0a Labels, Items.
15f0: 20 20 20 20 77 68 65 72 65 0a 20 20 20 20 20 20 where.
1600: 20 20 4c 61 62 65 6c 73 2e 6c 61 62 65 6c 20 3d Labels.label =
1610: 20 27 6c 6f 63 61 6c 68 6f 73 74 40 72 70 6c 3a 'localhost@rpl:
1620: 62 72 61 6e 63 68 27 0a 20 20 20 20 61 6e 64 20 branch'. and
1630: 4c 61 62 65 6c 73 2e 6c 61 62 65 6c 49 64 20 3d Labels.labelId =
1640: 20 4c 61 62 65 6c 4d 61 70 2e 6c 61 62 65 6c 49 LabelMap.labelI
1650: 64 0a 20 20 20 20 61 6e 64 20 4c 61 62 65 6c 4d d. and LabelM
1660: 61 70 2e 69 74 65 6d 49 64 20 3d 20 49 74 65 6d ap.itemId = Item
1670: 73 2e 69 74 65 6d 49 64 0a 20 20 20 20 4f 52 44 s.itemId. ORD
1680: 45 52 20 42 59 20 2b 74 72 6f 76 65 2c 20 2b 70 ER BY +trove, +p
1690: 61 74 74 65 72 6e 0a 20 20 7d 0a 7d 20 7b 64 6f attern. }.} {do
16a0: 75 62 6c 65 20 2e 2a 3a 72 75 6e 74 69 6d 65 20 uble .*:runtime
16b0: 64 6f 75 62 6c 65 3a 72 75 6e 74 69 6d 65 20 2e double:runtime .
16c0: 2a 3a 72 75 6e 74 69 6d 65 20 64 6f 75 62 6c 65 *:runtime double
16d0: 3a 73 6f 75 72 63 65 20 2e 2a 3a 72 75 6e 74 69 :source .*:runti
16e0: 6d 65 7d 0a 0a 66 69 6e 69 73 68 5f 74 65 73 74 me}..finish_test
16f0: 0a .