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
|
#!/usr/bin/env tarantool
test = require("sqltester")
test:plan(7)
--!./tcltestrunner.lua
-- 2005-01-11
--
-- The author disclaims copyright to this source code. In place of
-- a legal notice, here is a blessing:
--
-- May you do good and not evil.
-- May you find forgiveness for yourself and forgive others.
-- May you share freely, never taking more than you give.
--
-------------------------------------------------------------------------
-- This file implements regression tests for sql library. The
-- focus of this file is testing the CREATE INDEX statement.
--
-- ["set","testdir",[["file","dirname",["argv0"]]]]
-- ["source",[["testdir"],"\/tester.tcl"]]
-- Create a table with a large number of columns
--
local COL_NUM = 123 -- was 1000
local ROW_NUM = 100 -- was 100
test:do_test(
"index2-1.1",
function()
local sql_parts = {"CREATE TABLE t1(id INT primary key"}
for i = 1, COL_NUM, 1 do
table.insert(sql_parts, "c"..i .. ' INT')
end
local sql = table.concat(sql_parts, ",")..");"
return test:execsql(sql)
end, {
-- <index2-1.1>
-- </index2-1.1>
})
test:do_test(
"index2-1.2",
function()
local sql_parts = {"INSERT INTO t1 VALUES(1"}
for i = 1, COL_NUM, 1 do
table.insert(sql_parts, ""..i)
end
local sql = table.concat(sql_parts, ",")..");"
return test:execsql(sql)
end, {
-- <index2-1.2>
-- </index2-1.2>
})
test:do_execsql_test(
"index2-1.3",
[[
SELECT c123 FROM t1
]], {
-- <index2-1.3>
123
-- </index2-1.3>
})
test:do_test(
"index2-1.4",
function()
test:execsql("START TRANSACTION")
for j = 1, ROW_NUM, 1 do
local sql_parts = {"INSERT INTO t1 VALUES(".. ((j * 10000) + 1)}
for i = 2, COL_NUM+1, 1 do
table.insert(sql_parts, ""..((j * 10000) + i))
end
local sql = table.concat(sql_parts, ",")..");"
test:execsql(sql)
end
test:execsql "COMMIT"
return test:execsql "SELECT count(*) FROM t1"
end, {
-- <index2-1.4>
ROW_NUM + 1
-- </index2-1.4>
})
test:do_execsql_test(
"index2-1.5",
"SELECT round(sum(c"..COL_NUM..")) FROM t1", {
-- <index2-1.5>
10000*ROW_NUM*(ROW_NUM+1)/2 + (COL_NUM+1)*(ROW_NUM+1)-1
-- </index2-1.5>
})
-- Create indices with many columns
--
test:do_test(
"index2-2.1",
function()
local sql_parts = {"CREATE INDEX t1i1 ON t1(c1"}
for i = 2, COL_NUM, 1 do
table.insert(sql_parts, "c"..i)
end
local sql = table.concat(sql_parts, ",")..");"
return test:execsql(sql)
end, {
-- <index2-2.1>
-- </index2-2.1>
})
test:do_test(
"index2-2.2",
function()
test:execsql "EXPLAIN SELECT c9 FROM t1 ORDER BY c1, c2, c3, c4, c5"
return test:execsql "SELECT c9 FROM t1 ORDER BY c1, c2, c3, c4, c5, c6 LIMIT 5"
end, {
-- <index2-2.2>
9, 10010, 20010, 30010, 40010
-- </index2-2.2>
})
test:finish_test()
|