Item_sum_distinct::clear(): Assertion `tree != 0' failed in maria-5.3-mwl89

Bug #715034 reported by Philip Stoev
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MariaDB
Fix Released
Undecided
Timour Katchaounov

Bug Description

not reproducible in maria-5.3

mysqld: item_sum.cc:1053: virtual void Item_sum_distinct::clear(): Assertion `tree != 0' failed.

#8 0x006b0d98 in __assert_fail () from /lib/libc.so.6
#9 0x081de625 in Item_sum_distinct::clear (this=0xae72f870) at item_sum.cc:1053
#10 0x08308c64 in JOIN::reinit (this=0xae76e588) at sql_select.cc:1757
#11 0x0830b830 in mysql_select (thd=0xae97c58, rref_pointer_array=0xae72f72c, tables=0xae749788, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0,
    group=0x0, having=0x0, proc_param=0x0, select_options=2147764741, result=0xae74a270, unit=0xae749480, select_lex=0xae72f628) at sql_select.cc:2616
#12 0x08332f4a in mysql_explain_union (thd=0xae97c58, unit=0xae749480, result=0xae74a270) at sql_select.cc:19315
#13 0x08332c4d in select_describe (join=0xae764070, need_tmp_table=false, need_order=false, distinct=false,
    message=0x88ad73c "Impossible WHERE noticed after reading const tables") at sql_select.cc:19275
#14 0x0831a5ad in return_zero_rows (join=0xae764070, result=0xae74a270, tables=0xae72e808, fields=..., send_row=false, select_options=2147764740,
    info=0x88ad73c "Impossible WHERE noticed after reading const tables", having=0x0) at sql_select.cc:8718
#15 0x083094f6 in JOIN::exec (this=0xae764070) at sql_select.cc:1917
#16 0x0830bad1 in mysql_select (thd=0xae97c58, rref_pointer_array=0xae996f4, tables=0xae72e808, wild_num=1, fields=..., conds=0xae749a90, og_num=0,
    order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147764740, result=0xae74a270, unit=0xae99354, select_lex=0xae995f0)
    at sql_select.cc:2667
#17 0x08332f4a in mysql_explain_union (thd=0xae97c58, unit=0xae99354, result=0xae74a270) at sql_select.cc:19315
#18 0x082a1e6e in execute_sqlcom_select (thd=0xae97c58, all_tables=0xae72e808) at sql_parse.cc:5049
#19 0x08298ffb in mysql_execute_command (thd=0xae97c58) at sql_parse.cc:2234
#20 0x082a4584 in mysql_parse (thd=0xae97c58,
    rawbuf=0xae72d9f8 "EXPLAIN\nSELECT *\nFROM ( SELECT * FROM t2 ) AS a2\nJOIN t1 ON t1.f3\nWHERE t1.f11 IN ( SELECT 'd' )\nAND (SELECT DISTINCT SUM( DISTINCT f3 ) FROM t1)", length=146, found_semicolon=0xae8ff228) at sql_parse.cc:6077
#21 0x08296c93 in dispatch_command (command=COM_QUERY, thd=0xae97c58, packet=0xaeafd49 "", packet_length=147) at sql_parse.cc:1210
#22 0x08296140 in do_command (thd=0xae97c58) at sql_parse.cc:903
#23 0x0829321e in handle_one_connection (arg=0xae97c58) at sql_connect.cc:1154
#24 0x00821919 in start_thread () from /lib/libpthread.so.0
#25 0x0076acce in clone () from /lib/libc.so.6

revision-id: <email address hidden>
date: 2011-02-03 17:00:28 +0200
build-date: 2011-02-08 09:35:02 +0200
revno: 2883
branch-nick: maria-5.3-mwl89

test case:

CREATE TABLE t2 ( f2 int(11)) ;

CREATE TABLE t1 ( f3 int(11), f11 varchar(1), KEY (f3)) ;
INSERT INTO t1 VALUES ('6','m'),('4','c');

EXPLAIN
SELECT *
FROM ( SELECT * FROM t2 ) AS a2
JOIN t1 ON t1.f3
WHERE t1.f11 IN ( SELECT 'd' )
AND (SELECT DISTINCT SUM( DISTINCT f3 ) FROM t1) ;

Related branches

Changed in maria:
milestone: none → 5.3
assignee: nobody → Timour Katchaounov (timour)
Changed in maria:
status: New → In Progress
Revision history for this message
Timour Katchaounov (timour) wrote :

Slightly simplified version of the test query:

EXPLAIN
SELECT *
FROM ( SELECT * FROM t2 ) AS a2
WHERE (SELECT distinct SUM(distinct f3 ) FROM t1);

Revision history for this message
Timour Katchaounov (timour) wrote :

Analysis:

The failed assert is a result of calling Item_sum_distinct::clear() on an
incomplete object for which Item_sum_distinct::setup() was not yet
called.

The reason is that JOIN::exec for the outer query calls JOIN::reinit()
for all its subqueries, which in turn calls clear() for all aggregate functions
of the subqueries. The call stack is:
JOIN::reinit
mysql_select
mysql_explain_union
select_describe
JOIN::exec
mysql_select
mysql_explain_union

This assert doesn't fail in the main 5.3 because constant subqueries
are being executed during the optimize phase of the outer query,
thus the Unique object is created before calling JOIN::exec for the
outer query, and Item_sum_distinct::clear() actually cleans the
Unique object.

Solution:
The best solution is the obvious one - aubstitute the assert with
a test whether Item_sum_distinct::tree is NULL.

Changed in maria:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.