MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / setup_ref_array

Method setup_ref_array

sql/sql_lex.cc:2095–2159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2093
2094
2095bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
2096{
2097 // find_order_in_list() may need some extra space, so multiply by two.
2098 order_group_num*= 2;
2099
2100 // create_distinct_group() may need some extra space
2101 const bool select_distinct= MY_TEST(options & SELECT_DISTINCT);
2102 if (select_distinct)
2103 {
2104 uint bitcount= 0;
2105 Item *item;
2106 List_iterator<Item> li(item_list);
2107 while ((item= li++))
2108 {
2109 /*
2110 Same test as in create_distinct_group, when it pushes new items to the
2111 end of ref_pointer_array. An extra test for 'fixed' which, at this
2112 stage, will be true only for columns inserted for a '*' wildcard.
2113 */
2114 if (item->fixed &&
2115 item->type() == Item::FIELD_ITEM &&
2116 item->field_type() == MYSQL_TYPE_BIT)
2117 ++bitcount;
2118 }
2119 order_group_num+= bitcount;
2120 }
2121
2122 /*
2123 We have to create array in prepared statement memory if it is
2124 prepared statement
2125 */
2126 Query_arena *arena= thd->stmt_arena;
2127 const uint n_elems= (n_sum_items +
2128 n_child_sum_items +
2129 item_list.elements +
2130 select_n_having_items +
2131 select_n_where_fields +
2132 order_group_num) * 5;
2133 DBUG_PRINT("info", ("setup_ref_array this %p %4u : %4u %4u %4u %4u %4u %4u",
2134 this,
2135 n_elems, // :
2136 n_sum_items,
2137 n_child_sum_items,
2138 item_list.elements,
2139 select_n_having_items,
2140 select_n_where_fields,
2141 order_group_num));
2142 if (!ref_pointer_array.is_null())
2143 {
2144 /*
2145 We need to take 'n_sum_items' into account when allocating the array,
2146 and this may actually increase during the optimization phase due to
2147 MIN/MAX rewrite in Item_in_subselect::single_value_transformer.
2148 In the usual case we can reuse the array from the prepare phase.
2149 If we need a bigger array, we must allocate a new one.
2150 */
2151 if (ref_pointer_array.size() >= n_elems)
2152 return false;

Callers

nothing calls this directly

Calls 5

typeMethod · 0.45
field_typeMethod · 0.45
is_nullMethod · 0.45
sizeMethod · 0.45
allocMethod · 0.45

Tested by

no test coverage detected