File: gh-2996-indexed-by.test.lua

package info (click to toggle)
tarantool 2.6.0-1.2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 85,396 kB
  • sloc: ansic: 513,775; cpp: 69,493; sh: 25,650; python: 19,190; perl: 14,973; makefile: 4,176; yacc: 1,329; sql: 1,074; pascal: 620; ruby: 190; awk: 18; lisp: 7
file content (161 lines) | stat: -rwxr-xr-x 4,159 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env tarantool
test = require("sqltester")
test:plan(13)

-- gh-2996 - INDEXED BY clause wasn't working.
-- This functional test ensures that execution of that type of
-- statement is correct.

test:execsql [[
    CREATE TABLE t1(a INT PRIMARY KEY, b INT);
    CREATE INDEX t1ix2 on t1(b);
    CREATE INDEX t1ix1 on t1(b);
]]

sample_size = 1000
local query = "INSERT INTO t1 VALUES "

for i = 1, sample_size do
    query = query  .. "(" .. i .. ", " .. i .. ")"
    if (i ~= sample_size) then
        query = query .. ","
    end
end

-- Fill our space with data
test:execsql(query)

test:do_execsql_test(
    "indexed-by-1.0",
    "SELECT b FROM t1 INDEXED BY t1ix1 WHERE b <= 5", {
        -- <indexed-by-1.0>
        1, 2, 3, 4, 5
    })

-- Make sure that SELECT works correctly when index exists.
test:do_eqp_test(
    "indexed-by-1.1",
    "SELECT b FROM t1 WHERE b <= 5", {
        -- <indexed-by-1.1>
        { 0, 0, 0, 'SEARCH TABLE T1 USING COVERING INDEX T1IX2 (B<?) (~262144 rows)' }
        -- <indexed-by-1.1>
    })

test:do_eqp_test(
    "indexed-by-1.2",
    "SELECT b FROM t1 INDEXED BY t1ix1 WHERE b <= 5", {
        -- <indexed-by-1.2>
        { 0, 0, 0, 'SEARCH TABLE T1 USING COVERING INDEX T1IX1 (B<?) (~262144 rows)' }
        -- <indexed-by-1.2>
    })

test:execsql [[
    DROP INDEX t1ix1 ON t1;
    DROP INDEX t1ix2 ON t1;
]]

-- Now make sure that when schema was changed (t1ix1 was dropped),
-- SELECT statement won't work.
test:do_catchsql_test(
    "indexed-by-1.3",
    "SELECT b FROM t1 INDEXED BY t1ix1 WHERE b <= 5", {
        -- <indexed-by-1.3>
        1, "No index 'T1IX1' is defined in space 'T1'"
        -- <indexed-by-1.3>
    })

test:do_catchsql_test(
    "indexed-by-1.4",
    "SELECT b FROM t1 INDEXED BY t1ix2 WHERE b <= 5", {
        -- <indexed-by-1.4>
        1, "No index 'T1IX2' is defined in space 'T1'"
        -- <indexed-by-1.4>
    })

-- Make sure that DELETE statement works correctly with INDEXED BY.
test:execsql [[
    CREATE INDEX t1ix2 ON t1(b);
    CREATE INDEX t1ix1 on t1(b);
]]

test:do_eqp_test(
    "indexed-by-1.5",
    "DELETE FROM t1 WHERE b <= 5", {
        -- <indexed-by-1.5>
        { 0, 0, 0, 'SEARCH TABLE T1 USING COVERING INDEX T1IX2 (B<?) (~262144 rows)' }
        -- <indexed-by-1.5>
    })

test:do_eqp_test(
    "indexed-by-1.6",
    "DELETE FROM t1 INDEXED BY t1ix1  WHERE b <= 5", {
        -- <indexed-by-1.6>
        { 0, 0, 0, 'SEARCH TABLE T1 USING COVERING INDEX T1IX1 (B<?) (~262144 rows)' }
        -- <indexed-by-1.6>
    })

test:execsql [[
    DROP INDEX t1ix1 ON t1;
    DROP INDEX t1ix2 ON t1;
]]

test:do_catchsql_test(
    "indexed-by-1.7",
    "DELETE FROM t1 INDEXED BY t1ix1 WHERE b <= 5", {
        -- <indexed-by-1.7>
        1, "No index 'T1IX1' is defined in space 'T1'"
        -- <indexed-by-1.7>
    })

test:do_catchsql_test(
    "indexed-by-1.8",
    "DELETE FROM t1 INDEXED BY t1ix2 WHERE b <= 5", {
        -- <indexed-by-1.8>
        1, "No index 'T1IX2' is defined in space 'T1'"
        -- <indexed-by-1.8>
    })

test:execsql [[
   CREATE INDEX t1ix2 ON t1(b);
   CREATE INDEX t1ix1 ON t1(b);
]]

test:do_eqp_test(
    "indexed-by-1.9",
    "UPDATE t1 SET b = 20 WHERE b = 10", {
        -- <indexed-by-1.9>
        { 0, 0, 0, 'SEARCH TABLE T1 USING COVERING INDEX T1IX2 (B=?) (~10 rows)' }
        -- <indexed-by-1.9>
    })

test:do_eqp_test(
    "indexed-by-1.10",
    "UPDATE t1 INDEXED BY t1ix1 SET b = 20 WHERE b = 10", {
        -- <indexed-by-1.10>
        { 0, 0, 0, 'SEARCH TABLE T1 USING COVERING INDEX T1IX1 (B=?) (~10 rows)' }
        -- <indexed-by-1.10>
    })

test:execsql [[
    DROP INDEX t1ix1 ON t1;
    DROP INDEX t1ix2 ON t1;
]]

test:do_catchsql_test(
    "indexed-by-1.11",
    "UPDATE t1 INDEXED BY t1ix1 SET b = 20 WHERE b = 10", {
        -- <indexed-by-1.11>
        1, "No index 'T1IX1' is defined in space 'T1'"
        -- <indexed-by-1.11>
    })

test:do_catchsql_test(
    "indexed-by-1.12",
    "UPDATE t1 INDEXED BY t1ix2 SET b = 20 WHERE b = 10", {
        -- <indexed-by-1.12>
        1, "No index 'T1IX2' is defined in space 'T1'"
        -- <indexed-by-1.12>
    })

test:finish_test()