List:Internals« Previous MessageNext Message »
From:Jay Pipes Date:February 26 2009 6:31pm
Subject:Removing Array custom vector allocation for semi-join subqueries
View as plain text  
I have been attempting to remove the templatized Array class in 
Drizzle/MySQL, defined in sql/sql_array.h in favor of the STL vector<> 
template container class.

The JOIN class has a member sj_subselects, defined as:

   Array<Item_in_subselect> sj_subselects;

I've run into an issue where I am uncertain how to instantiate a 
semijoin Item_in_subselect properly from within JOIN::prepare.  The 
constructors available for Item_in_subselect are as follows:

   Item_in_subselect(Item * left_expr, Select_Lex *select_lex);
   Item_in_subselect()
     :Item_exists_subselect(), left_expr_cache(0), first_execution(true),
     optimizer(0), abort_on_null(0), pushed_cond_guards(NULL),
     exec_method(NOT_TRANSFORMED), upper_item(0)
   {}

However, in JOIN::prepare, the following is what is used in order to add 
a (new?) Item_in_subselect to the Array:

select_lex->outer_select()->join->sj_subselects.append(session->mem_root, 
in_subs);

where "in_subs" is of type pointer to Item_in_subselect of the current 
subselect:

         in_subs= (Item_in_subselect*)subselect;

where "subselect" is defined as:

	Item_subselect *subselect= select_lex->master_unit()->item;

The Array<Item_in_subselect>::append method appears to simply assign the 
supplied pointer into the Array's storage buffer of pointers:

     buffer[n_elements++]= el;

So, Array is simply a block of mem-root-allocated pointers. Disregarding 
the mem-root allocation, I would presume that changing the sj_subselects 
definition from:

   Array<Item_in_subselect> sj_subselects;

to:

   std::vector<Item_in_subselect *> sj_subselects;

would produce an equivalent vector.

However, after changing the Array to std::vector<> semantics in 
JOIN::prepare and JOIN::flatten_subqueries, it appears that I cannot 
simply push an existing pointer into a vector, as one would presume. 
So, changing this:
 
select_lex->outer_select()->join->sj_subselects.append(session->mem_root, 
in_subs);

to:

select_lex->outer_select()->join->sj_subselects.push_back(in_subs);

Does not work.  There is some loss of state happening at some point.

So, I tried to make a copy of the in_subs instead of supplying a 
pointer, like so:

Item_in_subselect *sj_sub= new Item_in_subselect(in_subs->left_expr, 
in_subs->get_select_lex());

select_lex->outer_select()->join->sj_subselects.push_back(sj_sub);

This works better, but GDB vomits in Item_subselect::fix_fields(), 
complaining that the Item_subselect::engine->cols() is undefined...

If anyone has any advice or can spot a mistake in the logic above, I'd 
appreciate some assistance...

Cheers,

Jay
Thread
Removing Array custom vector allocation for semi-join subqueriesJay Pipes26 Feb
  • Re: Removing Array custom vector allocation for semi-join subqueriesKonstantin Osipov26 Feb
    • Re: Removing Array custom vector allocation for semi-join subqueriesJay Pipes26 Feb
  • Re: [Drizzle-discuss] Removing Array custom vector allocation forsemi-join subqueriesKonstantin Osipov26 Feb
    • Re: [Drizzle-discuss] Removing Array custom vector allocation forsemi-join subqueriesJay Pipes26 Feb
Re: [Drizzle-discuss] Removing Array custom vector allocation for semi-join subqueriesBrian Aker26 Feb
  • Re: [Drizzle-discuss] Removing Array custom vector allocation forsemi-join subqueriesMonty Taylor27 Feb
    • Re: [Drizzle-discuss] Removing Array custom vector allocation for semi-join subqueriesMARK CALLAGHAN27 Feb
      • Re: [Drizzle-discuss] Removing Array custom vector allocation forsemi-join subqueriesMonty Taylor27 Feb
        • Re: [Drizzle-discuss] Removing Array custom vector allocation forsemi-join subqueriesKonstantin Osipov27 Feb
          • Re: [Drizzle-discuss] Removing Array custom vector allocation for semi-join subqueriesMARK CALLAGHAN27 Feb
        • Re: [Drizzle-discuss] Removing Array custom vector allocation for semi-join subqueriesMARK CALLAGHAN27 Feb
          • Re: [Drizzle-discuss] Removing Array custom vector allocation forsemi-join subqueriesJim Starkey27 Feb
    • Re: [Drizzle-discuss] Removing Array custom vector allocation forsemi-join subqueriesMichael Widenius2 Mar
      • Re: [Drizzle-discuss] Removing Array custom vector allocation forsemi-join subqueriesJay Pipes2 Mar
      • Re: [Drizzle-discuss] Removing Array custom vector allocation forsemi-join subqueriesJim Starkey2 Mar
        • Re: [Drizzle-discuss] Removing Array custom vector allocation forsemi-join subqueriesKonstantin Osipov2 Mar
        • Re: [Drizzle-discuss] Removing Array custom vector allocation forsemi-join subqueriesMichael Widenius5 Mar
Re: [Drizzle-discuss] Removing Array custom vector allocation for semi-join subqueriesBrian Aker26 Feb