Debian Codegraph @

mysql-test/suite/x/t/admin_create_index_string.test

raw
1 ## generated
2
3 --source include/xplugin_preamble.inc
4 --source include/xplugin_create_user.inc
5
6 ## Test starts here
7 CREATE SCHEMA xtest DEFAULT CHARSET 'utf8mb4';
8
9 --let $xtest_file= $MYSQL_TMP_DIR/admin_create_index_string_mysqlx.xpl
10 --write_file $xtest_file
11 -->import assert_select.macro
12
13 -->quiet
14
15 ## Test data
16 -->stmtadmin create_collection {"schema":"xtest", "name":"books1"}
17 -->recvresult
18
19 -->macro Assert_use_of_index %COLL% %NAME% %COND%
20 callmacro Assert_select
21 possible_keys
22 %NAME%
23 EXPLAIN SELECT * FROM xtest.%COLL% USE INDEX(`%NAME%`) WHERE %COND%;
24 -->endmacro
25
26 -->macro Insert %COLL% %VALUE% %ERROR%
27 Mysqlx.Crud.Insert {
28 collection {
29 name: "%COLL%"
30 schema: "xtest"
31 }
32 data_model: DOCUMENT
33 row {
34 field {
35 type: LITERAL
36 literal {
37 type: V_STRING
38 v_string {
39 value: %VALUE%
40 }
41 }
42 }
43 }
44 }
45 -->expecterror %ERROR%
46 -->recvresult
47 -->endmacro
48
49
50 -->macro Create_index %COLLECTION% %INDEX% %UNIQUE% %DOCUMENT_PATH% %TYPE% %REQUIRED% %ERROR%
51 -->stmtadmin create_collection_index {"schema":"xtest", "collection":%COLLECTION%, "name": %INDEX%, "unique": %UNIQUE%, "constraint":{"member": %DOCUMENT_PATH%, "type": %TYPE%,"required": %REQUIRED%}}
52 -->expecterror %ERROR%
53 -->recvresult
54 -->endmacro
55
56 -->echo 1
57 -->callmacro Create_index "books1" "isbn" true "$.isbn" "TEXT(13)" false ER_SUCCESS
58
59
60 -->callmacro Insert books1 '{"_id": "one", "name": "The Bla", "isbn" : "9780262527804", "pages":30}' ER_SUCCESS
61 -->callmacro Insert books1 '{"_id": "two", "name": "The Bla II", "isbn" : "9780262527805"}' ER_SUCCESS
62 -->callmacro Insert books1 '{"_id": "three", "name": "The Bla III"}' ER_SUCCESS
63
64 -->callmacro Assert_use_of_index books1 isbn doc->'$.isbn' = '9780262527804'
65
66 -->callmacro Create_index "books1" "pages" true "$.pages" "INT" true ER_X_DOC_REQUIRED_FIELD_MISSING
67 -->callmacro Create_index "books1" "pages" true "$.pages" "INT" false ER_SUCCESS
68 -->callmacro Assert_use_of_index books1 pages doc->'$.pages' > 1
69
70 -->callmacro Create_index "books1" "name" true "$.name" "TEXT(80)" true ER_SUCCESS
71 -->callmacro Assert_use_of_index books1 name doc->'$.name' = 'The Bla'
72
73 -->callmacro Create_index "books1" "another name" true "$.name" "TEXT(80)" true ER_SUCCESS
74 -->callmacro Assert_use_of_index books1 another name doc->'$.name' = 'The Bla'
75
76 -->callmacro Create_index "books1" "name_char" true "$.name" "CHAR(64)" true ER_SUCCESS
77 -->callmacro Assert_use_of_index books1 name_char doc->'$.name' = 'The Bla'
78
79 -->callmacro Create_index "books1" "isbn_char" true "$.isbn" "CHAR" true ER_DATA_TOO_LONG
80
81 -->callmacro Insert books1 '{"_id": "four", "isbn": "9780262527809"}' ER_X_DOC_ID_MISSING
82
83
84 -->callmacro Create_index "books1" "datetime`;drop table" false "$.data.datetime" "DATETIME" false ER_SUCCESS
85
86 -->callmacro Create_index "books1" "_id" false "$.data.datetime" "DATETIME" false ER_SUCCESS
87
88 -->callmacro Create_index "books1" "aaa" true "$.da\ta.da\tetime" "DATETIME" false ER_X_CMD_ARGUMENT_VALUE
89
90 -->callmacro Create_index "books1" "" false "$.data.datetime" "DATETIME" false ER_X_CMD_ARGUMENT_VALUE
91
92 -->callmacro Create_index "books1" "aaa" false "$.data.datetime" "text(20);drop table" false ER_X_CMD_ARGUMENT_VALUE
93
94 -->callmacro Create_index "books1" "aaa" false "$.data.datetime" "varchar(20)" false ER_X_CMD_ARGUMENT_VALUE
95
96 -->callmacro Create_index "books1" "aaa" false "$.data!datetime" "INT" false ER_X_CMD_ARGUMENT_VALUE
97
98 -->callmacro Create_index "books1" "aaa" false "$.data' foo" "INT" false ER_X_CMD_ARGUMENT_VALUE
99
100 -->callmacro Create_index "books1" "aaa" false "data.datetime" "INT" false ER_X_CMD_ARGUMENT_VALUE
101
102
103 -->stmtadmin create_collection {"schema":"xtest", "name":"books0"}
104 -->recvresult
105
106 -->callmacro Insert books0 '{"_id": "one", "name": "The Bla", "isbn" : "9780262527804", "pages":30}' ER_SUCCESS
107 -->callmacro Insert books0 '{"_id": "two", "name": "The Bla Bla", "isbn" : "1280262527804", "pages":50}' ER_SUCCESS
108
109 -->stmtadmin create_collection_index {"schema":"xtest", "collection":"books0", "name":"mix", "unique":true, "fields":[{"field":"$.isbn", "type":"TEXT(80)", "required":false}, {"field":"$.pages", "type":"INT", "required":false}]}
110 -->recvresult
111 -->callmacro Assert_use_of_index books0 mix doc->'$.isbn' = '9780262527804' and doc->'$.pages' > 1
112
113 -->callmacro Create_index "books0" "name_charset" true "$.name" "CHAR(64) CHARSET latin1 COLLATE latin1_bin" true ER_SUCCESS
114 -->callmacro Assert_use_of_index books0 name_charset doc->'$.name' = 'The Bla'
115
116 -->callmacro Create_index "books0" "isbn_text_charset" true "$.isbn" "TEXT(64) COLLATE latin1_bin" true ER_SUCCESS
117 -->callmacro Assert_use_of_index books0 isbn_text_charset doc->'$.isbn' = '9780262527804'
118
119 -->stmtsql show create table xtest.books0
120 -->recvresult
121 EOF
122
123
124 --exec $MYSQLXTEST -ux_root --password='' --file=$xtest_file 2>&1
125
126
127 ## Cleanup
128 --source ../include/xplugin_cleanup.inc
129