Bug #71149 Assertion `((Item_result_field*)item)->result_field' fails in create_tmp_field
Submitted: 16 Dec 2013 9:37 Modified: 27 May 2014 8:56
Reporter: Elena Stepanova Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:5.6.15, 5.7.3-m13 OS:Any
Assigned to: CPU Architecture:Any

[16 Dec 2013 9:37] Elena Stepanova
Description:
mysql-5.6/sql/sql_tmp_table.cc:366: Field* create_tmp_field(THD*, TABLE*, Item*, Item::Type, Item***, Field**, Field**, bool, bool, bool, bool): Assertion `((Item_result_field*)item)->result_field' failed.
09:32:16 UTC - mysqld got signal 6 

#7  0x00007f2c1a9536c2 in __assert_fail () from /lib64/libc.so.6
#8  0x000000000084f0fd in create_tmp_field (thd=0x263bcf0, table=0x7f2c00056ce0, item=0x7f2c00005210, type=Item::STRING_ITEM, copy_func=0x7f2c0ee332a8, from_field=0x7f2c00057910, default_field=0x7f2c000578f0, group=false, modify_item=false, table_cant_handle_bit_fields=false, make_copy_field=true) at mysql-5.6/sql/sql_tmp_table.cc:366
#9  0x00000000008502f4 in create_tmp_table (thd=0x263bcf0, param=0x7f2c000548e0, fields=..., group=0x0, distinct=false, save_sum_fields=true, select_options=2147748608, rows_limit=18446744073709551615, table_alias=0xee1280 "") at mysql-5.6/sql/sql_tmp_table.cc:730
#10 0x00000000006f833d in Item_func_group_concat::setup (this=0x7f2c000542b8, thd=0x263bcf0) at mysql-5.6/sql/item_sum.cc:3507
#11 0x00000000006f943c in Aggregator_simple::setup (this=0x7f2c00054718, thd=0x263bcf0) at mysql-5.6/sql/item_sum.h:639
#12 0x00000000007b2470 in Item_sum::aggregator_setup (this=0x7f2c000542b8, thd=0x263bcf0) at mysql-5.6/sql/item_sum.h:493
#13 0x00000000007a8e94 in setup_sum_funcs (thd=0x263bcf0, func_ptr=0x7f2c00006580) at mysql-5.6/sql/sql_executor.cc:461
#14 0x000000000080da19 in JOIN::make_tmp_tables_info (this=0x7f2c00005ee8) at mysql-5.6/sql/sql_select.cc:5228
#15 0x000000000099a5ec in JOIN::optimize (this=0x7f2c00005ee8) at mysql-5.6/sql/sql_optimizer.cc:1012
#16 0x0000000000803e2b in mysql_execute_select (thd=0x263bcf0, select_lex=0x263e558, free_join=true) at mysql-5.6/sql/sql_select.cc:1086
#17 0x0000000000804164 in mysql_select (thd=0x263bcf0, tables=0x7f2c000057b0, wild_num=0, fields=..., conds=0x0, order=0x263e720, group=0x263e658, having=0x0, select_options=2147748608, result=0x7f2c00005ec0, unit=0x263df10, select_lex=0x263e558) at mysql-5.6/sql/sql_select.cc:1221
#18 0x0000000000802282 in handle_select (thd=0x263bcf0, result=0x7f2c00005ec0, setup_tables_done_option=0) at mysql-5.6/sql/sql_select.cc:110
#19 0x00000000007ddc89 in execute_sqlcom_select (thd=0x263bcf0, all_tables=0x7f2c000057b0) at mysql-5.6/sql/sql_parse.cc:5094
#20 0x00000000007d6d63 in mysql_execute_command (thd=0x263bcf0) at mysql-5.6/sql/sql_parse.cc:2642
#21 0x00000000007e0247 in mysql_parse (thd=0x263bcf0, rawbuf=0x7f2c00004fd0 "SELECT GROUP_CONCAT(i,'foo') AS f1 FROM t1 GROUP BY 'a' WITH ROLLUP", length=67, parser_state=0x7f2c0ee34eb0) at mysql-5.6/sql/sql_parse.cc:6235
#22 0x00000000007d3fbb in dispatch_command (command=COM_QUERY, thd=0x263bcf0, packet=0x2710971 "SELECT GROUP_CONCAT(i,'foo') AS f1 FROM t1 GROUP BY 'a' WITH ROLLUP", packet_length=67) at mysql-5.6/sql/sql_parse.cc:1334
#23 0x00000000007d31a4 in do_command (thd=0x263bcf0) at mysql-5.6/sql/sql_parse.cc:1036
#24 0x000000000079e0a0 in do_handle_one_connection (thd_arg=0x263bcf0) at mysql-5.6/sql/sql_connect.cc:982
#25 0x000000000079dbd7 in handle_one_connection (arg=0x263bcf0) at mysql-5.6/sql/sql_connect.cc:898
#26 0x0000000000d421a5 in pfs_spawn_thread (arg=0x268c1c0) at mysql-5.6/storage/perfschema/pfs.cc:1858
#27 0x00007f2c1bb3f0db in start_thread () from /lib64/libpthread.so.0
#28 0x00007f2c1aa0c90d in clone () from /lib64/libc.so.6

How to repeat:
CREATE TABLE t1 ( i INT );
INSERT INTO t1 VALUES (1),(2);

SELECT GROUP_CONCAT(i,'foo') AS f1 FROM t1 GROUP BY 'a' WITH ROLLUP;
[16 Dec 2013 10:37] MySQL Verification Team
Hello Elena,

Thank you for the bug report and test case.
Verified as described on 5.6.15/5.7.3 debug builds(works fine on release builds).

Thanks,
Umesh
[16 Dec 2013 15:02] MySQL Verification Team
looks like a duplicate of my internal
Bug 17607155 - ASSERTION FAILED: ((ITEM_RESULT_FIELD*)ITEM)->RESULT_FIELD

My testcase was:

---
drop table if exists `t`;
create table `t`(`a` int)engine=innodb;
insert `t` values(1);
select '' from `t` group by 1 with rollup having group_concat('');
---
[27 May 2014 8:56] Erlend Dahl
This has now been fixed in 5.6.20 and 5.7.5.
[6 Aug 2014 17:40] Laurynas Biveinis
$ bzr log -n0 -r 5950
------------------------------------------------------------
revno: 5950
committer: Chaithra Gopalareddy <chaithra.gopalareddy@oracle.com>
branch nick: mysql-5.6
timestamp: Wed 2014-05-21 12:46:14 +0530
message:
  Bug#11760197:INCORRECT RESULTS WITH COUNT DISTINCT AND BIG_TABLES
  Problem:
  When big_tables is enabled, COUNT DISTINCT on simple join with
  constant equality condition gives wrong result.
  
  Analysis:-
  In case of count distinct with sql_big_tables enable, optimizer
  saves data in myisam file instead of heap unique tree.
  When a constant equality condition is present, it does not
  detect duplicate field values when inserting the records into the
  temporary table.
  
  Original solution:
  While creating temporary table, allow creations of fields for constant
  items. When we have distinct query, this will make sure the duplicate
  value filtered out when inserting rows in the temporary table.
  
  Side Effects:
  Bug#17555462 - SELECT DISTINCT OF VIEW WITH CONSTANT STRING
                 RETURNS WRONG RESULT
  Problem:
  In a temporary table if a field is created for a const ref_item,
  and if this ref_item is a reference over a constant string and not
  on a field results are not as expected.
  
  Analysis:
  This is a regression from the patch for Bug#11760197. Post
  this bugfix, a field gets created in temporary table
  even for const_item's. If the const_item is of type Item_ref,
  while creating the temporary field, item->result_field
  is made to point to the newly created field.
  While the original item would hold the constant's value,
  the new field created while changing ref's to use temporary
  fields, will not be having the value.
  As a result we loose the value when fetching the results.
  
  In similar lines:
  Bug #17607155: ASSERTION FAILED: ((ITEM_RESULT_FIELD*)ITEM)->RESULT_FIELD
  Bug #17957913: ASSERTION `((ITEM_RESULT_FIELD*)ITEM)->RESULT_FIELD' FAILS
                 IN CREATE_TMP_FIELD
  Problem:
  Query having a GROUP BY CLAUSE with ROLLUP modifier and a
  GROUP_CONCAT/COUNT(DISTINCT) function with constant expression,
  causes an assert.
  
  Analysis:
  The GROUP_CONCAT/COUNT(DISTINCT) uses its own temporary table.
  When ROLLUP is present it creates the second copy of temporary
  table.
  This copy receives the same list of arguments that original
  group_concat/count(distinct) does which will help to copy
  the content of the result_field for the function under
  GROUP_CONCAT/COUNT from  the first temporary table to the second
  temporary table.
  
  In the case, when constant item is present, result_field will carry
  null value. After the fix for Bug#11760197, while creating field
  for second temporary table as result_field for the constant
  expression is not set, it asserts.
  
  Bug#17634335: SELECT DISTINCT...GROUP BY RETURNS WRONG RESULTS
  IN SOME CASES
  
  Query creating temporary table to find the distinct value and has
  constant value in projected list doesn't give correct result.
  
  Analysis:
  After the fix for Bug#11760197 const_items also were created as
  part of temporary tables. In the call to remove_duplicates() an
  assumption against the same was made which resulted in the above bug.
  
  All the above bugs were side effects of the fix made for Bug#11760197.
  
  Current solution:
  Distinct of a constant value will always be the constant value and
  count distinct of the same will always be one. Based on this,
  a new variable const_distinct is introduced. If enabled, temporary
  table is not created and aggregation is also avoided as the result
  will always be one.
  
  Works in similar lines to always_null.
[6 Aug 2014 17:44] Laurynas Biveinis
See bug 52582, bug 70657.