| 1 |
## Test of visibility of prepare statement in prerformace schema |
| 2 |
|
| 3 |
## Preamble |
| 4 |
--source include/no_ps_protocol.inc |
| 5 |
--source ../include/have_performance_schema_statements.inc |
| 6 |
--source include/xplugin_preamble.inc |
| 7 |
--source include/xplugin_create_user.inc |
| 8 |
## Test starts here |
| 9 |
|
| 10 |
--write_file $MYSQL_TMP_DIR/prep_stmt_perf_schema.xpl |
| 11 |
-->import assert_select.macro |
| 12 |
-->import assert_variable.macro |
| 13 |
-->quiet |
| 14 |
|
| 15 |
-->macro_varg Prepare_and_verify_in_perf_schema %SQL% |
| 16 |
echo # Prepare stmt; |
| 17 |
Mysqlx.Prepare.Prepare { |
| 18 |
stmt_id: 42 |
| 19 |
%VAR_ARGS% |
| 20 |
} |
| 21 |
-->recvtype Mysqlx.Ok be-quiet |
| 22 |
|
| 23 |
callmacro Assert_select |
| 24 |
sql_text |
| 25 |
%SQL% |
| 26 |
SELECT sql_text FROM performance_schema.prepared_statements_instances WHERE `STATEMENT_ID`=mysqlx_get_prepared_statement_id(42); |
| 27 |
|
| 28 |
|
| 29 |
echo # Deallocate the stmt; |
| 30 |
Mysqlx.Prepare.Deallocate { |
| 31 |
stmt_id: 42 |
| 32 |
} |
| 33 |
-->recvtype Mysqlx.Ok be-quiet |
| 34 |
|
| 35 |
callmacro Assert_select |
| 36 |
count_sql_text |
| 37 |
0 |
| 38 |
SELECT count(sql_text) AS count_sql_text FROM performance_schema.prepared_statements_instances; |
| 39 |
|
| 40 |
-->endmacro |
| 41 |
|
| 42 |
-->echo |
| 43 |
-->echo ## 1. Verify SQL preparation in performance_schema |
| 44 |
-->echo ## 2. Verify Crud.Find preparation in performance_schema |
| 45 |
-->echo # a. check find on a table |
| 46 |
-->echo # b. check find on a collection |
| 47 |
-->echo ## 3. Verify Crud.Insert preparation in performance_schema |
| 48 |
-->echo # a. success for execute with one parameter |
| 49 |
-->echo # b. success for execute with two parameters (more than needed) |
| 50 |
|
| 51 |
|
| 52 |
title =Setup database; |
| 53 |
stmtadmin create_collection {"schema": "xtest", "name":"coll"}; |
| 54 |
recvresult; |
| 55 |
|
| 56 |
|
| 57 |
title = 1. Verify SQL; |
| 58 |
|
| 59 |
callmacro Prepare_and_verify_in_perf_schema |
| 60 |
SELECT 1 |
| 61 |
stmt: { |
| 62 |
type: STMT |
| 63 |
stmt_execute: { |
| 64 |
stmt: "SELECT 1" |
| 65 |
} |
| 66 |
}; |
| 67 |
|
| 68 |
|
| 69 |
title = 2.a. Verify Crud.Find on a table; |
| 70 |
|
| 71 |
callmacro Prepare_and_verify_in_perf_schema |
| 72 |
SELECT '42' FROM `mysql`.`user` |
| 73 |
stmt: { |
| 74 |
type: FIND |
| 75 |
find: { |
| 76 |
collection { name: "user" schema: "mysql" } |
| 77 |
data_model: TABLE |
| 78 |
projection { |
| 79 |
source { |
| 80 |
type: LITERAL literal { |
| 81 |
type: V_OCTETS v_octets { |
| 82 |
value: "42" |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
}; |
| 89 |
|
| 90 |
|
| 91 |
title = 2.b. Verify Crud.Find on a collection; |
| 92 |
|
| 93 |
callmacro Prepare_and_verify_in_perf_schema |
| 94 |
SELECT doc FROM `coll` |
| 95 |
stmt: { |
| 96 |
type: FIND |
| 97 |
find: { |
| 98 |
collection { name: "coll" } |
| 99 |
data_model: DOCUMENT |
| 100 |
} |
| 101 |
}; |
| 102 |
|
| 103 |
|
| 104 |
title = 3.a. Verify Crud.Insert on a table with literal; |
| 105 |
|
| 106 |
callmacro Prepare_and_verify_in_perf_schema |
| 107 |
INSERT INTO `coll` (`doc`) VALUES ('{\"_id\":\"1\", \"pupil\":\"Alice\", \"pet\":\"cat\"}') |
| 108 |
stmt: { |
| 109 |
type: INSERT |
| 110 |
insert: { |
| 111 |
collection { name: "coll" } |
| 112 |
data_model: TABLE |
| 113 |
projection { name: "doc" } |
| 114 |
row { |
| 115 |
field { |
| 116 |
type: LITERAL literal { |
| 117 |
type: V_STRING v_string { |
| 118 |
value: '{"_id":"1", "pupil":"Alice", "pet":"cat"}' |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
}; |
| 125 |
|
| 126 |
|
| 127 |
title = 3.b. Verify Crud.Insert on a collection with literal; |
| 128 |
|
| 129 |
callmacro Prepare_and_verify_in_perf_schema |
| 130 |
INSERT INTO `coll` (doc) VALUES ((SELECT JSON_INSERT(`_DERIVED_TABLE_`.`value`,'$._id',CONVERT(MYSQLX_GENERATE_DOCUMENT_ID(@@AUTO_INCREMENT_OFFSET,@@AUTO_INCREMENT_INCREMENT,JSON_CONTAINS_PATH(`_DERIVED_TABLE_`.`value`,'one','$._id')) USING utf8mb4)) FROM (SELECT '{\"_id\":\"1\", \"pupil\":\"Alice\", \"pet\":\"cat\"}' AS `value`) AS `_DERIVED_TABLE_`)) |
| 131 |
stmt: { |
| 132 |
type: INSERT |
| 133 |
insert: { |
| 134 |
collection { name: "coll" } |
| 135 |
data_model: DOCUMENT |
| 136 |
row { |
| 137 |
field { |
| 138 |
type: LITERAL literal { |
| 139 |
type: V_STRING v_string { |
| 140 |
value: '{"_id":"1", "pupil":"Alice", "pet":"cat"}' |
| 141 |
} |
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
}; |
| 147 |
|
| 148 |
|
| 149 |
title = 3.c. Verify Crud.Insert on a collection with object; |
| 150 |
|
| 151 |
callmacro Prepare_and_verify_in_perf_schema |
| 152 |
INSERT INTO `coll` (doc) VALUES ((SELECT JSON_INSERT(`_DERIVED_TABLE_`.`value`,'$._id',CONVERT(MYSQLX_GENERATE_DOCUMENT_ID(@@AUTO_INCREMENT_OFFSET,@@AUTO_INCREMENT_INCREMENT,JSON_CONTAINS_PATH(`_DERIVED_TABLE_`.`value`,'one','$._id')) USING utf8mb4)) FROM (SELECT JSON_OBJECT('pupil',?,'pet',?) AS `value`) AS `_DERIVED_TABLE_`)) |
| 153 |
stmt: { |
| 154 |
type: INSERT |
| 155 |
insert: { |
| 156 |
collection { name: "coll" } |
| 157 |
data_model: DOCUMENT |
| 158 |
row { |
| 159 |
field { |
| 160 |
type: OBJECT object { |
| 161 |
fld { |
| 162 |
key: "pupil" |
| 163 |
value { |
| 164 |
type: PLACEHOLDER position: 0 |
| 165 |
} |
| 166 |
} |
| 167 |
fld { |
| 168 |
key: "pet" |
| 169 |
value { |
| 170 |
type: PLACEHOLDER position: 1 |
| 171 |
} |
| 172 |
} |
| 173 |
} |
| 174 |
} |
| 175 |
} |
| 176 |
} |
| 177 |
}; |
| 178 |
|
| 179 |
EOF |
| 180 |
|
| 181 |
CREATE DATABASE xtest; |
| 182 |
--exec $MYSQLXTEST -ux_root --password='' --schema xtest --file=$MYSQL_TMP_DIR/prep_stmt_perf_schema.xpl 2>&1 |
| 183 |
|
| 184 |
## Cleanup |
| 185 |
--source ../include/xplugin_cleanup.inc |