Skip to content

Commit 7224fcd

Browse files
committed
mv tests to create_table_queries.go
1 parent dad9d62 commit 7224fcd

File tree

2 files changed

+142
-142
lines changed

2 files changed

+142
-142
lines changed

enginetest/queries/create_table_queries.go

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,148 @@ var CreateTableQueries = []WriteQueryTest{
327327
}
328328

329329
var CreateTableScriptTests = []ScriptTest{
330+
{
331+
// https://github.com/dolthub/dolt/issues/9316
332+
Name: "CREATE TABLE with constraints AS SELECT osticket repro",
333+
SkipPrepared: true, // SHOW KEYS with WHERE clause doesn't work with prepared statements
334+
SetUpScript: []string{
335+
"CREATE TABLE ost_form_entry (id INT PRIMARY KEY, object_id INT, object_type VARCHAR(1))",
336+
"CREATE TABLE ost_form_entry_values (entry_id INT, field_id INT, value VARCHAR(100), value_id INT)",
337+
"CREATE TABLE ost_form_field (id INT PRIMARY KEY)",
338+
"INSERT INTO ost_form_entry VALUES (1, 100, 'U'), (2, 101, 'U'), (3, 102, 'X')",
339+
"INSERT INTO ost_form_entry_values VALUES (1, 1, '[email protected]', 1000), (2, 1, '[email protected]', 1001), (3, 2, 'other', 2000)",
340+
"INSERT INTO ost_form_field VALUES (1), (2)",
341+
},
342+
Assertions: []ScriptTestAssertion{
343+
{
344+
Query: `CREATE TABLE IF NOT EXISTS ost_user__cdata (
345+
PRIMARY KEY (user_id)
346+
) DEFAULT CHARSET=utf8 AS
347+
SELECT
348+
entry.object_id as user_id,
349+
MAX(IF(field.id='1',coalesce(ans.value_id, ans.value),NULL)) as email
350+
FROM ost_form_entry entry
351+
JOIN ost_form_entry_values ans
352+
ON ans.entry_id = entry.id
353+
JOIN ost_form_field field
354+
ON field.id=ans.field_id
355+
WHERE entry.object_type='U' GROUP BY entry.object_id`,
356+
},
357+
{
358+
Query: "SELECT * FROM ost_user__cdata ORDER BY user_id",
359+
Expected: []sql.Row{
360+
{100, "1000"},
361+
{101, "1001"},
362+
},
363+
},
364+
{
365+
Query: "SHOW KEYS FROM ost_user__cdata WHERE Key_name = 'PRIMARY'",
366+
Expected: []sql.Row{
367+
{"ost_user__cdata", 0, "PRIMARY", 1, "user_id", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil},
368+
},
369+
},
370+
},
371+
},
372+
{
373+
// https://github.com/dolthub/dolt/issues/9316
374+
Name: "CREATE TABLE with constraints AS SELECT",
375+
SkipPrepared: true,
376+
SetUpScript: []string{
377+
"CREATE TABLE t1 (a int not null, b varchar(10))",
378+
"INSERT INTO t1 VALUES (1, 'one'), (2, 'two'), (3, 'three')",
379+
"CREATE TABLE source (id int, name varchar(20))",
380+
"INSERT INTO source VALUES (1, 'alice'), (2, 'bob'), (3, 'charlie')",
381+
"CREATE TABLE override_src (a bigint, b int)",
382+
"INSERT INTO override_src VALUES (100, 200)",
383+
"CREATE TABLE base (a int, b varchar(10))",
384+
"INSERT INTO base VALUES (1, 'alpha'), (2, 'beta')",
385+
"CREATE TABLE multi_src (id int, email varchar(50), age int)",
386+
"INSERT INTO multi_src VALUES (1, '[email protected]', 25), (2, '[email protected]', 30)",
387+
},
388+
Assertions: []ScriptTestAssertion{
389+
{
390+
Query: "CREATE TABLE t2 (PRIMARY KEY(a)) SELECT * FROM t1",
391+
},
392+
{
393+
Query: "SELECT * FROM t2 ORDER BY a",
394+
Expected: []sql.Row{
395+
{1, "one"},
396+
{2, "two"},
397+
{3, "three"},
398+
},
399+
},
400+
{
401+
Query: "SHOW KEYS FROM t2 WHERE Key_name = 'PRIMARY'",
402+
Expected: []sql.Row{
403+
{"t2", 0, "PRIMARY", 1, "a", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil},
404+
},
405+
},
406+
{
407+
Query: "CREATE TABLE indexed (KEY(name)) SELECT * FROM source",
408+
},
409+
{
410+
Query: "SELECT * FROM indexed ORDER BY id",
411+
Expected: []sql.Row{
412+
{1, "alice"},
413+
{2, "bob"},
414+
{3, "charlie"},
415+
},
416+
},
417+
{
418+
Query: "SHOW KEYS FROM indexed WHERE Key_name = 'name'",
419+
Expected: []sql.Row{
420+
{"indexed", 1, "name", 1, "name", nil, 0, nil, nil, "YES", "BTREE", "", "", "YES", nil},
421+
},
422+
},
423+
{
424+
Query: "CREATE TABLE override (a TINYINT NOT NULL) SELECT a, b FROM override_src",
425+
},
426+
{
427+
Query: "SELECT * FROM override",
428+
Expected: []sql.Row{
429+
{int8(100), 200},
430+
},
431+
},
432+
{
433+
Query: "SHOW CREATE TABLE override",
434+
Expected: []sql.Row{
435+
{"override", "CREATE TABLE `override` (\n `a` tinyint NOT NULL,\n `b` int\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"},
436+
},
437+
},
438+
{
439+
Query: "CREATE TABLE uniq (UNIQUE KEY(a)) SELECT * FROM base",
440+
},
441+
{
442+
Query: "SELECT * FROM uniq ORDER BY a",
443+
Expected: []sql.Row{
444+
{1, "alpha"},
445+
{2, "beta"},
446+
},
447+
},
448+
{
449+
Query: "SHOW KEYS FROM uniq WHERE Key_name = 'a'",
450+
Expected: []sql.Row{
451+
{"uniq", 0, "a", 1, "a", nil, 0, nil, nil, "YES", "BTREE", "", "", "YES", nil},
452+
},
453+
},
454+
{
455+
Query: "CREATE TABLE multi_idx (PRIMARY KEY(id), KEY(email), KEY(age)) SELECT * FROM multi_src",
456+
},
457+
{
458+
Query: "SELECT * FROM multi_idx ORDER BY id",
459+
Expected: []sql.Row{
460+
{1, "[email protected]", 25},
461+
{2, "[email protected]", 30},
462+
},
463+
},
464+
{
465+
Query: "SELECT COUNT(*) FROM information_schema.statistics WHERE table_name = 'multi_idx'",
466+
Expected: []sql.Row{
467+
{3},
468+
},
469+
},
470+
},
471+
},
330472
{
331473
// https://github.com/dolthub/dolt/issues/6682
332474
Name: "display width for numeric types",

enginetest/queries/script_queries.go

Lines changed: 0 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -122,148 +122,6 @@ type ScriptTestAssertion struct {
122122
// Unlike other engine tests, ScriptTests must be self-contained. No other tables are created outside the definition of
123123
// the tests.
124124
var ScriptTests = []ScriptTest{
125-
{
126-
// https://github.com/dolthub/dolt/issues/9316
127-
Name: "CREATE TABLE with constraints AS SELECT osticket repro",
128-
SkipPrepared: true, // SHOW KEYS with WHERE clause doesn't work with prepared statements
129-
SetUpScript: []string{
130-
"CREATE TABLE ost_form_entry (id INT PRIMARY KEY, object_id INT, object_type VARCHAR(1))",
131-
"CREATE TABLE ost_form_entry_values (entry_id INT, field_id INT, value VARCHAR(100), value_id INT)",
132-
"CREATE TABLE ost_form_field (id INT PRIMARY KEY)",
133-
"INSERT INTO ost_form_entry VALUES (1, 100, 'U'), (2, 101, 'U'), (3, 102, 'X')",
134-
"INSERT INTO ost_form_entry_values VALUES (1, 1, '[email protected]', 1000), (2, 1, '[email protected]', 1001), (3, 2, 'other', 2000)",
135-
"INSERT INTO ost_form_field VALUES (1), (2)",
136-
},
137-
Assertions: []ScriptTestAssertion{
138-
{
139-
Query: `CREATE TABLE IF NOT EXISTS ost_user__cdata (
140-
PRIMARY KEY (user_id)
141-
) DEFAULT CHARSET=utf8 AS
142-
SELECT
143-
entry.object_id as user_id,
144-
MAX(IF(field.id='1',coalesce(ans.value_id, ans.value),NULL)) as email
145-
FROM ost_form_entry entry
146-
JOIN ost_form_entry_values ans
147-
ON ans.entry_id = entry.id
148-
JOIN ost_form_field field
149-
ON field.id=ans.field_id
150-
WHERE entry.object_type='U' GROUP BY entry.object_id`,
151-
},
152-
{
153-
Query: "SELECT * FROM ost_user__cdata ORDER BY user_id",
154-
Expected: []sql.Row{
155-
{100, "1000"},
156-
{101, "1001"},
157-
},
158-
},
159-
{
160-
Query: "SHOW KEYS FROM ost_user__cdata WHERE Key_name = 'PRIMARY'",
161-
Expected: []sql.Row{
162-
{"ost_user__cdata", 0, "PRIMARY", 1, "user_id", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil},
163-
},
164-
},
165-
},
166-
},
167-
{
168-
// https://github.com/dolthub/dolt/issues/9316
169-
Name: "CREATE TABLE with constraints AS SELECT",
170-
SkipPrepared: true,
171-
SetUpScript: []string{
172-
"CREATE TABLE t1 (a int not null, b varchar(10))",
173-
"INSERT INTO t1 VALUES (1, 'one'), (2, 'two'), (3, 'three')",
174-
"CREATE TABLE source (id int, name varchar(20))",
175-
"INSERT INTO source VALUES (1, 'alice'), (2, 'bob'), (3, 'charlie')",
176-
"CREATE TABLE override_src (a bigint, b int)",
177-
"INSERT INTO override_src VALUES (100, 200)",
178-
"CREATE TABLE base (a int, b varchar(10))",
179-
"INSERT INTO base VALUES (1, 'alpha'), (2, 'beta')",
180-
"CREATE TABLE multi_src (id int, email varchar(50), age int)",
181-
"INSERT INTO multi_src VALUES (1, '[email protected]', 25), (2, '[email protected]', 30)",
182-
},
183-
Assertions: []ScriptTestAssertion{
184-
{
185-
Query: "CREATE TABLE t2 (PRIMARY KEY(a)) SELECT * FROM t1",
186-
},
187-
{
188-
Query: "SELECT * FROM t2 ORDER BY a",
189-
Expected: []sql.Row{
190-
{1, "one"},
191-
{2, "two"},
192-
{3, "three"},
193-
},
194-
},
195-
{
196-
Query: "SHOW KEYS FROM t2 WHERE Key_name = 'PRIMARY'",
197-
Expected: []sql.Row{
198-
{"t2", 0, "PRIMARY", 1, "a", nil, 0, nil, nil, "", "BTREE", "", "", "YES", nil},
199-
},
200-
},
201-
{
202-
Query: "CREATE TABLE indexed (KEY(name)) SELECT * FROM source",
203-
},
204-
{
205-
Query: "SELECT * FROM indexed ORDER BY id",
206-
Expected: []sql.Row{
207-
{1, "alice"},
208-
{2, "bob"},
209-
{3, "charlie"},
210-
},
211-
},
212-
{
213-
Query: "SHOW KEYS FROM indexed WHERE Key_name = 'name'",
214-
Expected: []sql.Row{
215-
{"indexed", 1, "name", 1, "name", nil, 0, nil, nil, "YES", "BTREE", "", "", "YES", nil},
216-
},
217-
},
218-
{
219-
Query: "CREATE TABLE override (a TINYINT NOT NULL) SELECT a, b FROM override_src",
220-
},
221-
{
222-
Query: "SELECT * FROM override",
223-
Expected: []sql.Row{
224-
{int8(100), 200},
225-
},
226-
},
227-
{
228-
Query: "SHOW CREATE TABLE override",
229-
Expected: []sql.Row{
230-
{"override", "CREATE TABLE `override` (\n `a` tinyint NOT NULL,\n `b` int\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"},
231-
},
232-
},
233-
{
234-
Query: "CREATE TABLE uniq (UNIQUE KEY(a)) SELECT * FROM base",
235-
},
236-
{
237-
Query: "SELECT * FROM uniq ORDER BY a",
238-
Expected: []sql.Row{
239-
{1, "alpha"},
240-
{2, "beta"},
241-
},
242-
},
243-
{
244-
Query: "SHOW KEYS FROM uniq WHERE Key_name = 'a'",
245-
Expected: []sql.Row{
246-
{"uniq", 0, "a", 1, "a", nil, 0, nil, nil, "YES", "BTREE", "", "", "YES", nil},
247-
},
248-
},
249-
{
250-
Query: "CREATE TABLE multi_idx (PRIMARY KEY(id), KEY(email), KEY(age)) SELECT * FROM multi_src",
251-
},
252-
{
253-
Query: "SELECT * FROM multi_idx ORDER BY id",
254-
Expected: []sql.Row{
255-
{1, "[email protected]", 25},
256-
{2, "[email protected]", 30},
257-
},
258-
},
259-
{
260-
Query: "SELECT COUNT(*) FROM information_schema.statistics WHERE table_name = 'multi_idx'",
261-
Expected: []sql.Row{
262-
{3},
263-
},
264-
},
265-
},
266-
},
267125
{
268126
// https://github.com/dolthub/dolt/issues/9987
269127
Name: "GROUP BY nil pointer dereference in Dispose when Next() never called",

0 commit comments

Comments
 (0)