[MDEV-18000] VALUES (...) ORDER BY crashes MariaDB Created: 2018-12-13  Updated: 2020-08-31  Resolved: 2020-08-31

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

Type: Bug Priority: Major
Reporter: Federico Razzoli Assignee: Igor Babaev
Resolution: Duplicate Votes: 0
Labels: values

Issue Links:
Duplicate
duplicates MDEV-17894 Assertion `(thd->lex)->current_select... Closed

 Description   

This syntax crashes the server:

VALUES (1), (2), (3)
ORDER BY 1;

I don't know if this is supposed to be supported, because I couldn't find any documentation. But in all cases, note that this syntax is supported by Oracle, so it is at least a reasonable attempt.



 Comments   
Comment by Alice Sherepa [ 2018-12-13 ]

Thank you for the report!
It crashes server, on debug server - assertion

 VALUES (1), (2), (3) ORDER BY 1; 

mysqld: /git/10.3/sql/sql_yacc.yy:12791: int MYSQLparse(THD*): Assertion `sel->master_unit()->fake_select_lex' failed.
181213 17:21:34 [ERROR] mysqld got signal 6 ;
 
linux/raise.c:54(__GI_raise)[0x7f0ce1bd5428]
stdlib/abort.c:91(__GI_abort)[0x7f0ce1bd702a]
assert/assert.c:92(__assert_fail_base)[0x7f0ce1bcdbd7]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dc82)[0x7f0ce1bcdc82]
sql/sql_yacc.yy:12792(MYSQLparse(THD*))[0x56023c681a17]
sql/sql_parse.cc:10102(parse_sql(THD*, Parser_state*, Object_creation_ctx*, bool))[0x56023c15c39a]
sql/sql_parse.cc:8044(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x56023c14ff03]
sql/sql_parse.cc:1852(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x56023c12ae30]
sql/sql_parse.cc:1395(do_command(THD*))[0x56023c127fc8]
sql/sql_connect.cc:1402(do_handle_one_connection(CONNECT*))[0x56023c47af0b]
sql/sql_connect.cc:1309(handle_one_connection)[0x56023c47a8e8]
perfschema/pfs.cc:1864(pfs_spawn_thread)[0x56023d7a1ab7]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba)[0x7f0ce28126ba]
x86_64/clone.S:111(clone)[0x7f0ce1ca741d]
 
Query (0x62b0000003d0): VALUES (1), (2), (3) ORDER BY 1

 VALUES (1), (2), (3) LIMIT 1; 

mysqld: /git/10.3/sql/sql_yacc.yy:12833: int MYSQLparse(THD*): Assertion `(thd->lex)->current_select' failed.
181213 17:22:35 [ERROR] mysqld got signal 6 ;
 
linux/raise.c:54(__GI_raise)[0x7f42570a3428]
stdlib/abort.c:91(__GI_abort)[0x7f42570a502a]
assert/assert.c:92(__assert_fail_base)[0x7f425709bbd7]
/lib/x86_64-linux-gnu/libc.so.6(+0x2dc82)[0x7f425709bc82]
sql/sql_yacc.yy:12841(MYSQLparse(THD*))[0x55e8a4b0fe84]
sql/sql_parse.cc:10102(parse_sql(THD*, Parser_state*, Object_creation_ctx*, bool))[0x55e8a45ea39a]
sql/sql_parse.cc:8044(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x55e8a45ddf03]
sql/sql_parse.cc:1852(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x55e8a45b8e30]
sql/sql_parse.cc:1395(do_command(THD*))[0x55e8a45b5fc8]
sql/sql_connect.cc:1402(do_handle_one_connection(CONNECT*))[0x55e8a4908f0b]
sql/sql_connect.cc:1309(handle_one_connection)[0x55e8a49088e8]
perfschema/pfs.cc:1864(pfs_spawn_thread)[0x55e8a5c2fab7]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba)[0x7f4257ce06ba]
x86_64/clone.S:111(clone)[0x7f425717541d]
 
Query (0x62b0000003d0): VALUES (1), (2), (3) limit 1

Comment by Federico Razzoli [ 2018-12-24 ]

In the meanwhile, I suggest to document the VALUES statement, so it will be clear if ORDER BY is supposed to be allowed or not.

Comment by Elena Stepanova [ 2018-12-24 ]

There is a separate task for it, MDEV-18004.

Comment by Federico Razzoli [ 2020-08-25 ]

In MariaDB 10.5 VALUES ORDER BY works as expected and no crash happens.

I suppose this bug should be closed.

MariaDB [test]> SELECT VERSION();
+----------------+
| VERSION()      |
+----------------+
| 10.5.5-MariaDB |
+----------------+
1 row in set (0.000 sec)
 
MariaDB [test]> VALUES (1), (2), (3)  ORDER BY 1;
+---+
| 1 |
+---+
| 1 |
| 2 |
| 3 |
+---+
3 rows in set (0.000 sec)
 
MariaDB [test]> VALUES (1), (2), (3)  ORDER BY 1 DESC;
+---+
| 1 |
+---+
| 3 |
| 2 |
| 1 |
+---+
3 rows in set (0.000 sec)

Generated at Thu Feb 08 08:40:45 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.