[MDEV-25379] JSON_TABLE: ERROR ON clauses are ignored if a column is not on select list Created: 2021-04-09  Updated: 2021-04-21  Resolved: 2021-04-14

Status: Closed
Project: MariaDB Server
Component/s: JSON
Affects Version/s: N/A
Fix Version/s: 10.6.0

Type: Bug Priority: Blocker
Reporter: Elena Stepanova Assignee: Alexey Botchkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-17399 Add support for JSON_TABLE Closed

 Description   

This query returns an error as it is supposed to, because of ERROR ON EMPTY clause for column a:

MariaDB [test]> SELECT * FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
ERROR 4175 (HY000): Field 'a' can't be set for JSON_TABLE 'jt'.

However, if don't select the column a, it works:

MariaDB [test]> SELECT o FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
+------+
| o    |
+------+
|    1 |
+------+
1 row in set (0.001 sec)
 
MariaDB [test]> SELECT COUNT(*) FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
+----------+
| COUNT(*) |
+----------+
|        1 |
+----------+
1 row in set (0.001 sec)

Same applies for ERROR ON ERROR clauses.

It is not quite clear from the standard what the expected behavior is. It only says that the clauses have the same semantics as for JSON_VALUE, but for JSON_VALUE the situation when the value is not selected is not applicable. Still, from the common sense alone, it just doesn't look right:

bb-10.6-mdev17399-hf 160bd1691

MariaDB [test]> SELECT * FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
ERROR 4175 (HY000): Field 'a' can't be set for JSON_TABLE 'jt'.
 
MariaDB [test]> SELECT COUNT(*) FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
+----------+
| COUNT(*) |
+----------+
|        1 |
+----------+
1 row in set (0.001 sec)

MySQL 8.0.23 returns an error for all queries above:

MySQL 8.0.23

MySQL [(none)]> SELECT * FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
ERROR 3665 (22035): Missing value for JSON_TABLE column 'a'
MySQL [(none)]> SELECT o FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
ERROR 3665 (22035): Missing value for JSON_TABLE column 'a'
MySQL [(none)]> SELECT COUNT(*) FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
ERROR 3665 (22035): Missing value for JSON_TABLE column 'a'



 Comments   
Comment by Alexey Botchkov [ 2021-04-13 ]

fixing patch https://github.com/MariaDB/server/commit/cea5e01ee5feffbcf2a7446241a69cef58ee8e9f

Comment by Sergei Petrunia [ 2021-04-13 ]

Updated patch by Alexey: https://github.com/MariaDB/server/commit/e1dfe60e8024e2bfa07e735b17cff69cec0b5be7

Comment by Sergei Petrunia [ 2021-04-13 ]

Review:

Is there anything that prevents from just unpacking into table->record[0]?
(If you hit a DBUG_ASSERT with this, you can use dbug_tmp_use_all_columns)
I think the code would be simpler if it just unpacks all columns into
table->record[0].

The patch should also add a comment that ha_json_table::fill_column_values()
unpacks all columns in order to hit possible errors.

Comment by Alexey Botchkov [ 2021-04-14 ]

newer patch
https://github.com/MariaDB/server/commit/35f28a46b856ac5d1758033ea7ab67025e17e0d1

Comment by Sergei Petrunia [ 2021-04-14 ]

Ok to push the latest

Generated at Thu Feb 08 09:37:15 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.