[MDEV-19301] Assertion `!is_valid_datetime() || fraction_remainder(((item->decimals) < (6) ? (item->decimals) : (6))) == 0' failed in Datetime_truncation_not_needed::Datetime_truncation_not_needed Created: 2019-04-22  Updated: 2022-07-21  Resolved: 2019-08-06

Status: Closed
Project: MariaDB Server
Component/s: Temporal Types
Affects Version/s: 10.4
Fix Version/s: 10.4.8

Type: Bug Priority: Critical
Reporter: Elena Stepanova Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-29149 Assertion `!is_valid_datetime() || fr... Confirmed

 Description   

SELECT NULLIF( CAST( 1012.5 AS DATE ), 1 );

10.4 a65d3b2c

mysqld: /data/src/10.4/sql/sql_type.cc:978: Datetime_truncation_not_needed::Datetime_truncation_not_needed(THD*, Item*, date_conv_mode_t): Assertion `!is_valid_datetime() || fraction_remainder(((item->decimals) < (6) ? (item->decimals) : (6))) == 0' failed.
190422 15:28:36 [ERROR] mysqld got signal 6 ;
 
#7  0x00007f7053b2dee2 in __assert_fail () from /lib/x86_64-linux-gnu/libc.so.6
#8  0x0000555bba99c8eb in Datetime_truncation_not_needed::Datetime_truncation_not_needed (this=0x7f704dca5650, thd=0x7f703c000b00, item=0x7f703c015d48, mode=...) at /data/src/10.4/sql/sql_type.cc:976
#9  0x0000555bbaa47df7 in Datetime_truncation_not_needed::Datetime_truncation_not_needed (this=0x7f704dca5650, thd=0x7f703c000b00, item=0x7f703c015d48, mode=...) at /data/src/10.4/sql/sql_type.h:2295
#10 0x0000555bbab1d1ee in Item_func_nullif::date_op (this=0x7f703c015f28, thd=0x7f703c000b00, ltime=0x7f704dca5aa8, fuzzydate=...) at /data/src/10.4/sql/item_cmpfunc.cc:2897
#11 0x0000555bba9a5831 in Type_handler_temporal_result::Item_func_hybrid_field_type_get_date (this=0x555bbbe2f3b8 <type_handler_newdate>, thd=0x7f703c000b00, item=0x7f703c015f28, warn=0x7f704dca5700, ltime=0x7f704dca5aa8, fuzzydate=...) at /data/src/10.4/sql/sql_type.cc:4800
#12 0x0000555bba9a49ae in Type_handler::Item_func_hybrid_field_type_get_date_with_warn (this=0x555bbbe2f3b8 <type_handler_newdate>, thd=0x7f703c000b00, item=0x7f703c015f28, ltime=0x7f704dca5aa8, mode=...) at /data/src/10.4/sql/sql_type.cc:4421
#13 0x0000555bba781573 in Item_func_hybrid_field_type::get_date (this=0x7f703c015f28, thd=0x7f703c000b00, to=0x7f704dca5aa8, mode=...) at /data/src/10.4/sql/item_func.h:775
#14 0x0000555bba9a9de1 in Type_handler::Item_send_date (this=0x555bbbe2f3b8 <type_handler_newdate>, item=0x7f703c015f28, protocol=0x7f703c0010c8, buf=0x7f704dca5aa0) at /data/src/10.4/sql/sql_type.cc:6738
#15 0x0000555bba9b5eb6 in Type_handler_temporal_with_date::Item_send (this=0x555bbbe2f3b8 <type_handler_newdate>, item=0x7f703c015f28, protocol=0x7f703c0010c8, buf=0x7f704dca5aa0) at /data/src/10.4/sql/sql_type.h:5301
#16 0x0000555bba684092 in Item::send (this=0x7f703c015f28, protocol=0x7f703c0010c8, buffer=0x7f704dca5aa0) at /data/src/10.4/sql/item.h:1035
#17 0x0000555bba67ee32 in Protocol::send_result_set_row (this=0x7f703c0010c8, row_items=0x7f703c015948) at /data/src/10.4/sql/protocol.cc:1024
#18 0x0000555bba72cd08 in select_send::send_data (this=0x7f703c016a98, items=...) at /data/src/10.4/sql/sql_class.cc:3006
#19 0x0000555bba7ebe93 in JOIN::exec_inner (this=0x7f703c016ac0) at /data/src/10.4/sql/sql_select.cc:4256
#20 0x0000555bba7eb7ae in JOIN::exec (this=0x7f703c016ac0) at /data/src/10.4/sql/sql_select.cc:4170
#21 0x0000555bba7ece60 in mysql_select (thd=0x7f703c000b00, tables=0x0, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7f703c016a98, unit=0x7f703c004a30, select_lex=0x7f703c015800) at /data/src/10.4/sql/sql_select.cc:4602
#22 0x0000555bba7dd3f4 in handle_select (thd=0x7f703c000b00, lex=0x7f703c004968, result=0x7f703c016a98, setup_tables_done_option=0) at /data/src/10.4/sql/sql_select.cc:424
#23 0x0000555bba7a6c8d in execute_sqlcom_select (thd=0x7f703c000b00, all_tables=0x0) at /data/src/10.4/sql/sql_parse.cc:6602
#24 0x0000555bba79c263 in mysql_execute_command (thd=0x7f703c000b00) at /data/src/10.4/sql/sql_parse.cc:3891
#25 0x0000555bba7aaa13 in mysql_parse (thd=0x7f703c000b00, rawbuf=0x7f703c015740 "SELECT NULLIF( CAST( 1012.5 AS DATE ), 1 )", length=42, parser_state=0x7f704dca7180, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:8154
#26 0x0000555bba79646a in dispatch_command (command=COM_QUERY, thd=0x7f703c000b00, packet=0x7f703c00a8a1 "", packet_length=42, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:1832
#27 0x0000555bba794c50 in do_command (thd=0x7f703c000b00) at /data/src/10.4/sql/sql_parse.cc:1365
#28 0x0000555bba90d033 in do_handle_one_connection (connect=0x555bbe8e65b0) at /data/src/10.4/sql/sql_connect.cc:1398
#29 0x0000555bba90cda4 in handle_one_connection (arg=0x555bbe8e65b0) at /data/src/10.4/sql/sql_connect.cc:1301
#30 0x0000555bbad312f5 in pfs_spawn_thread (arg=0x555bbe9d8980) at /data/src/10.4/storage/perfschema/pfs.cc:1862
#31 0x00007f7055c22494 in start_thread (arg=0x7f704dca8700) at pthread_create.c:333
#32 0x00007f7053bea93f in clone () from /lib/x86_64-linux-gnu/libc.so.6

Non-debug build doesn't crash, just produces a number of warning/notes:

SELECT NULLIF( CAST( 1012.5 AS DATE ), 1 );
NULLIF( CAST( 1012.5 AS DATE ), 1 )
2000-10-12
Warnings:
Note	1292	Truncated incorrect date value: '1012.5'
Warning	1292	Truncated incorrect datetime value: '1'
Note	1292	Truncated incorrect date value: '1012.5'

10.3 doesn't crash and produces only one warning:

10.3 765ae6e8

SELECT NULLIF( CAST( 1012.5 AS DATE ), 1 );
NULLIF( CAST( 1012.5 AS DATE ), 1 )
2000-10-12
Warnings:
Warning	1292	Incorrect datetime value: '1'



 Comments   
Comment by Alexander Barkov [ 2019-08-06 ]

A related problem presents in 10.4:

SELECT CAST( 1012.5 AS DATE)*1.0;

+---------------------------+
| CAST( 1012.5 AS DATE)*1.0 |
+---------------------------+
|                20001012.5 |
+---------------------------+

Notice, the non-zero fractional part is wrong. Pre-10.4 versions correctly return `20001012.0`.

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