Skip to content

Commit 4743ba0

Browse files
committed
Bug #11827369: ASSERTION FAILED: !THD->LEX->CONTEXT_ANALYSIS_ONLY
Manual up-merge from 5.1 to 5.5.
2 parents f57cba0 + 2993c29 commit 4743ba0

5 files changed

Lines changed: 30 additions & 10 deletions

File tree

sql/item.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -472,7 +472,7 @@ Item::Item(THD *thd, Item *item):
472472
fixed(item->fixed),
473473
is_autogenerated_name(item->is_autogenerated_name),
474474
collation(item->collation),
475-
with_subselect(item->with_subselect),
475+
with_subselect(item->has_subquery()),
476476
cmp_context(item->cmp_context)
477477
{
478478
next= thd->free_list; // Put in free list

sql/item.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef ITEM_INCLUDED
22
#define ITEM_INCLUDED
33

4-
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
4+
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
55
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -1249,6 +1249,11 @@ class Item {
12491249
Return TRUE if the item points to a column of an outer-joined table.
12501250
*/
12511251
virtual bool is_outer_field() const { DBUG_ASSERT(fixed); return FALSE; }
1252+
1253+
/**
1254+
Checks if this item or any of its decendents contains a subquery.
1255+
*/
1256+
virtual bool has_subquery() const { return with_subselect; }
12521257
};
12531258

12541259

@@ -2528,6 +2533,10 @@ class Item_ref :public Item_ident
25282533
Field *get_tmp_table_field()
25292534
{ return result_field ? result_field : (*ref)->get_tmp_table_field(); }
25302535
Item *get_tmp_table_item(THD *thd);
2536+
bool const_item() const
2537+
{
2538+
return (*ref)->const_item() && (used_tables() == 0);
2539+
}
25312540
table_map used_tables() const
25322541
{
25332542
return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables();
@@ -2603,6 +2612,13 @@ class Item_ref :public Item_ident
26032612
return (*ref)->is_outer_field();
26042613
}
26052614

2615+
/**
2616+
Checks if the item tree that ref points to contains a subquery.
2617+
*/
2618+
virtual bool has_subquery() const
2619+
{
2620+
return (*ref)->has_subquery();
2621+
}
26062622
};
26072623

26082624

sql/item_cmpfunc.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -4366,7 +4366,7 @@ Item_cond::fix_fields(THD *thd, Item **ref)
43664366
const_item_cache= FALSE;
43674367
}
43684368
with_sum_func= with_sum_func || item->with_sum_func;
4369-
with_subselect|= item->with_subselect;
4369+
with_subselect|= item->has_subquery();
43704370
if (item->maybe_null)
43714371
maybe_null=1;
43724372
}
@@ -4691,7 +4691,7 @@ longlong Item_func_isnull::val_int()
46914691
Handle optimization if the argument can't be null
46924692
This has to be here because of the test in update_used_tables().
46934693
*/
4694-
if (!used_tables_cache && !with_subselect)
4694+
if (const_item_cache)
46954695
return cached_value;
46964696
return args[0]->is_null() ? 1: 0;
46974697
}
@@ -4700,7 +4700,7 @@ longlong Item_is_not_null_test::val_int()
47004700
{
47014701
DBUG_ASSERT(fixed == 1);
47024702
DBUG_ENTER("Item_is_not_null_test::val_int");
4703-
if (!used_tables_cache && !with_subselect)
4703+
if (const_item_cache)
47044704
{
47054705
owner->was_null|= (!cached_value);
47064706
DBUG_PRINT("info", ("cached: %ld", (long) cached_value));
@@ -4721,10 +4721,12 @@ longlong Item_is_not_null_test::val_int()
47214721
*/
47224722
void Item_is_not_null_test::update_used_tables()
47234723
{
4724+
const_item_cache= false;
47244725
if (!args[0]->maybe_null)
47254726
{
47264727
used_tables_cache= 0; /* is always true */
47274728
cached_value= (longlong) 1;
4729+
const_item_cache= true;
47284730
}
47294731
else
47304732
{
@@ -4733,6 +4735,7 @@ void Item_is_not_null_test::update_used_tables()
47334735
{
47344736
/* Remember if the value is always NULL or never NULL */
47354737
cached_value= (longlong) !args[0]->is_null();
4738+
const_item_cache= true;
47364739
}
47374740
}
47384741
}
@@ -4986,6 +4989,7 @@ Item_func_regex::fix_fields(THD *thd, Item **ref)
49864989
args[1]->fix_fields(thd, args + 1)) || args[1]->check_cols(1))
49874990
return TRUE; /* purecov: inspected */
49884991
with_sum_func=args[0]->with_sum_func || args[1]->with_sum_func;
4992+
with_subselect= args[0]->has_subquery() || args[1]->has_subquery();
49894993
max_length= 1;
49904994
decimals= 0;
49914995

sql/item_func.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -221,7 +221,7 @@ Item_func::fix_fields(THD *thd, Item **ref)
221221
used_tables_cache|= item->used_tables();
222222
not_null_tables_cache|= item->not_null_tables();
223223
const_item_cache&= item->const_item();
224-
with_subselect|= item->with_subselect;
224+
with_subselect|= item->has_subquery();
225225
}
226226
}
227227
fix_length_and_dec();

sql/sql_select.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7449,7 +7449,7 @@ remove_const(JOIN *join,ORDER *first_order, COND *cond,
74497449
*simple_order=0; // Must do a temp table to sort
74507450
else if (!(order_tables & not_const_tables))
74517451
{
7452-
if (order->item[0]->with_subselect &&
7452+
if (order->item[0]->has_subquery() &&
74537453
!(join->select_lex->options & SELECT_DESCRIBE))
74547454
order->item[0]->val_str(&order->item[0]->str_value);
74557455
DBUG_PRINT("info",("removing: %s", order->item[0]->full_name()));

0 commit comments

Comments
 (0)