@@ -22,10 +22,10 @@ SELECT 2 MEMBER OF ('["1","2","3"]');
2222# 4. SQL NULL propagation checks
2323SELECT NULL MEMBER OF ('[1,2,3]');
2424NULL MEMBER OF ('[1,2,3]')
25- NULL
25+ 0
2626SELECT NULL MEMBER OF ('[1,2,3]') IS NULL;
2727NULL MEMBER OF ('[1,2,3]') IS NULL
28- 1
28+ 0
2929SELECT 1 MEMBER OF (NULL);
30301 MEMBER OF (NULL)
3131NULL
@@ -71,17 +71,17 @@ id val 2 MEMBER OF (val)
71713 NULL NULL
7272SELECT id, val, NULL MEMBER OF (val) FROM t1;
7373id val NULL MEMBER OF (val)
74- 1 [1, 2, 3] NULL
75- 2 [4, 5, 6] NULL
74+ 1 [1, 2, 3] 0
75+ 2 [4, 5, 6] 0
76763 NULL NULL
7777CREATE TABLE t2 (candidate INT);
7878INSERT INTO t2 VALUES (2), (4), (NULL);
7979SELECT candidate, val, candidate MEMBER OF (val) FROM t1, t2 ORDER BY id, candidate;
8080candidate val candidate MEMBER OF (val)
81- NULL [1, 2, 3] NULL
81+ NULL [1, 2, 3] 0
82822 [1, 2, 3] 1
83834 [1, 2, 3] 0
84- NULL [4, 5, 6] NULL
84+ NULL [4, 5, 6] 0
85852 [4, 5, 6] 0
86864 [4, 5, 6] 1
8787NULL NULL NULL
@@ -112,14 +112,12 @@ EXECUTE stmt2 USING @candidate_json, @container_nested;
112112JSON_COMPACT(?) MEMBER OF (?)
1131131
114114DEALLOCATE PREPARE stmt2;
115- # 11. Malformed JSON-typed candidate test (using CHECK constraints bypass)
116- CREATE TABLE t3 (val JSON );
117- SET STATEMENT check_constraint_checks=0 FOR INSERT INTO t3 VALUES ('[1,2');
115+ # 11. Malformed LONGTEXT candidate test
116+ CREATE TABLE t3 (val LONGTEXT );
117+ INSERT INTO t3 VALUES ('[1,2');
118118SELECT val MEMBER OF ('[1,2,3]') FROM t3;
119119val MEMBER OF ('[1,2,3]')
120- NULL
121- Warnings:
122- Warning 4037 Unexpected end of JSON text in argument 2 to function 'json_contains'
120+ 0
123121DROP TABLE t3;
124122# 12. JSON scalar candidate test (type-strictness in passthrough branch)
125123CREATE TABLE t4 (val JSON);
@@ -142,13 +140,13 @@ SELECT 4 NOT MEMBER OF ('[1,2,3]');
142140SELECT '2' NOT MEMBER OF ('[1,2,3]');
143141'2' NOT MEMBER OF ('[1,2,3]')
1441421
145- # 13.4 NULL NOT MEMBER OF ('[1,2,3]') -> NULL (and IS NULL -> 1)
143+ # 13.4 NULL NOT MEMBER OF ('[1,2,3]') -> 1
146144SELECT NULL NOT MEMBER OF ('[1,2,3]');
147145NULL NOT MEMBER OF ('[1,2,3]')
148- NULL
146+ 1
149147SELECT NULL NOT MEMBER OF ('[1,2,3]') IS NULL;
150148NULL NOT MEMBER OF ('[1,2,3]') IS NULL
151- 1
149+ 0
152150# 13.5 1 NOT MEMBER OF (NULL) -> NULL (and IS NULL -> 1)
153151SELECT 1 NOT MEMBER OF (NULL);
1541521 NOT MEMBER OF (NULL)
@@ -168,9 +166,6 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1681661 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
169167Warnings:
170168Note 1003 select 1 not member of ('[1,2,3]') AS `1 NOT MEMBER OF ('[1,2,3]')`
171- SHOW WARNINGS;
172- Level Code Message
173- Note 1003 select 1 not member of ('[1,2,3]') AS `1 NOT MEMBER OF ('[1,2,3]')`
174169# 14. Prepared Statements twice execution for Section 6 nested cases
175170PREPARE stmt3 FROM 'SELECT JSON_COMPACT(\'[1,2]\') MEMBER OF (\'[[1,2],[3,4]]\')';
176171EXECUTE stmt3;
@@ -189,24 +184,24 @@ JSON_COMPACT('{"name":"John"}') MEMBER OF ('[{"name":"John"},{"name":"Joe"}]')
1891841
190185DEALLOCATE PREPARE stmt4;
191186#
192- # 15. Item 12 (mentor): null literal vs JSON null \u2014 type-strict distinctions
187+ # 15. null literal vs JSON null — type-strict distinctions
193188#
194189# SQL string 'null' inside a JSON string-array ["null"] -> 1 (matches the string)
195190select 'null' member of ('["null"]');
196191'null' member of ('["null"]')
1971921
198- # SQL NULL inside an array containing JSON null literal [null] -> NULL (SQL NULL propagates)
193+ # SQL NULL inside an array containing JSON null literal [null] -> 1
199194select null member of ('[null]');
200195null member of ('[null]')
201- NULL
196+ 1
202197# SQL string 'null' inside an array containing JSON null literal [null] -> 0 (type mismatch)
203198select 'null' member of ('[null]');
204199'null' member of ('[null]')
2052000
206- # SQL NULL inside a JSON string-array ["null"] -> NULL (SQL NULL propagates )
201+ # SQL NULL inside a JSON string-array ["null"] -> 0 (type mismatch )
207202select null member of ('["null"]');
208203null member of ('["null"]')
209- NULL
204+ 0
210205#
211206# 16. Regression test for Item 1 root-cause fix (stale a2_parsed cache bug)
212207# Before the fix, cross-join with non-constant candidate produced wrong results:
@@ -220,15 +215,15 @@ INSERT INTO t5 VALUES (1, '[1, 2, 3]'), (2, '[4, 5, 6]'), (3, NULL);
220215CREATE TABLE t6 (candidate INT);
221216INSERT INTO t6 VALUES (2), (4), (NULL);
222217# Exact results expected after fix:
223- # (NULL, [1,2,3]) -> NULL , (2, [1,2,3]) -> 1, (4, [1,2,3]) -> 0
224- # (NULL, [4,5,6]) -> NULL , (2, [4,5,6]) -> 0, (4, [4,5,6]) -> 1
218+ # (NULL, [1,2,3]) -> 0 , (2, [1,2,3]) -> 1, (4, [1,2,3]) -> 0
219+ # (NULL, [4,5,6]) -> 0 , (2, [4,5,6]) -> 0, (4, [4,5,6]) -> 1
225220# (NULL, NULL) -> NULL, (2, NULL) -> NULL, (4, NULL) -> NULL
226221SELECT candidate, val, candidate MEMBER OF (val) FROM t5, t6 ORDER BY id, candidate;
227222candidate val candidate MEMBER OF (val)
228- NULL [1, 2, 3] NULL
223+ NULL [1, 2, 3] 0
2292242 [1, 2, 3] 1
2302254 [1, 2, 3] 0
231- NULL [4, 5, 6] NULL
226+ NULL [4, 5, 6] 0
2322272 [4, 5, 6] 0
2332284 [4, 5, 6] 1
234229NULL NULL NULL
@@ -271,22 +266,23 @@ a j k t7.a MEMBER OF (t8.k)
2712661 [1,2,3] [1,2,3] 1
272267DROP TABLE t7, t8;
273268#
274- # 19. Item 6 (mentor): Single-column ROW_RESULT via stored function call
275- # Stored function calls (Item_func_sp) report ROW_RESULT with cols() == 1
276- # at the point val_str() inspects args[0]->result_type() — the goto-eval unwrap
277- # path is reached through ordinary stored function calls.
269+ # 19. Stored function tests (VARCHAR and JSON return types)
278270#
279- CREATE FUNCTION f_row_result() RETURNS VARCHAR(50)
280- RETURN JSON_OBJECT('value', 2, 'key', 'golden')//
281- SELECT f_row_result() MEMBER OF ('[{"key": "golden", "value": 2E0}]');
282- f_row_result() MEMBER OF ('[{"key": "golden", "value": 2E0}]')
271+ CREATE FUNCTION f() RETURNS VARCHAR(30) RETURN 'pony';
272+ SELECT f() MEMBER OF ('["sheep", "lamb", "pony"]');
273+ f() MEMBER OF ('["sheep", "lamb", "pony"]')
274+ 1
275+ SELECT JSON_QUOTE(f());
276+ JSON_QUOTE(f())
277+ "pony"
278+ DROP FUNCTION f;
279+ CREATE FUNCTION j_row_result() RETURNS JSON RETURN JSON_OBJECT('value', 2, 'key', 'golden');
280+ SELECT j_row_result() MEMBER OF ('[{"key": "golden", "value": 2E0}]');
281+ j_row_result() MEMBER OF ('[{"key": "golden", "value": 2E0}]')
2832820
284- SELECT JSON_QUOTE(f_row_result());
285- JSON_QUOTE(f_row_result())
286- "{\"value\": 2, \"key\": \"golden\"}"
287- DROP FUNCTION f_row_result;
283+ DROP FUNCTION j_row_result;
288284#
289- # 20. Item 4 (mentor): TIME_RESULT tests
285+ # 20. TIME_RESULT tests
290286# Verify that TIME values are quoted as JSON string literals without escaping.
291287#
292288SELECT JSON_QUOTE(CAST('12:30:00' AS TIME));
@@ -303,12 +299,41 @@ CAST('12:30:00' AS TIME) MEMBER OF ('["10:00:00", "12:30:00"]')
303299# Confirms literal multi-column ROW() constructors and RETURNS ROW(...) functions
304300# are rejected by check_cols(1) during fix_fields() at bind time.
305301#
306- CREATE FUNCTION f1_row() RETURNS ROW(a INT)
307- BEGIN
308- RETURN (SELECT 42);
309- END//
302+ CREATE FUNCTION f1_row() RETURNS ROW(a INT) RETURN (SELECT 42);
310303SELECT JSON_QUOTE(f1_row());
311304ERROR 21000: Operand should contain 1 column(s)
312305SELECT f1_row() MEMBER OF ('[42]');
313306ERROR 21000: Operand should contain 1 column(s)
314307DROP FUNCTION f1_row;
308+ #
309+ # 22. Optimizer trace test for condition processing
310+ #
311+ CREATE TABLE t (id INT PRIMARY KEY, x INT, j JSON);
312+ INSERT INTO t VALUES (1, 10, '[10, 20]'), (2, 20, '[10, 20]'), (3, 30, '[30, 40]');
313+ SET STATEMENT optimizer_trace='enabled=on' FOR SELECT * FROM t WHERE x=10 AND x MEMBER OF (j);
314+ id x j
315+ 1 10 [10, 20]
316+ SELECT JSON_DETAILED(JSON_EXTRACT(TRACE, '$**.condition_processing')) AS t FROM information_schema.OPTIMIZER_TRACE;
317+ t
318+ [
319+ {
320+ "condition": "WHERE",
321+ "original_condition": "t.x = 10 and t.x member of (t.j)",
322+ "steps":
323+ [
324+ {
325+ "transformation": "equality_propagation",
326+ "resulting_condition": "10 member of (t.j) and multiple equal(10, t.x)"
327+ },
328+ {
329+ "transformation": "constant_propagation",
330+ "resulting_condition": "10 member of (t.j) and multiple equal(10, t.x)"
331+ },
332+ {
333+ "transformation": "trivial_condition_removal",
334+ "resulting_condition": "10 member of (t.j) and multiple equal(10, t.x)"
335+ }
336+ ]
337+ }
338+ ]
339+ DROP TABLE t;
0 commit comments