~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_select.cc

  • Committer: Brian Aker
  • Date: 2009-06-08 16:52:16 UTC
  • mfrom: (1054.2.7 mordred)
  • Revision ID: brian@gaz-20090608165216-prwpfo3ixrsoo3ke
Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
static Item* part_of_refkey(Table *form,Field *field);
69
69
static bool cmp_buffer_with_ref(JOIN_TAB *tab);
70
70
static void change_cond_ref_to_const(Session *session,
71
 
                                     I_List<COND_CMP> *save_list,
 
71
                                     vector<COND_CMP>& save_list,
72
72
                                     Item *and_father,
73
73
                                     Item *cond,
74
74
                                     Item *field,
3733
3733
  and_level
3734
3734
*/
3735
3735
static void change_cond_ref_to_const(Session *session,
3736
 
                                     I_List<COND_CMP> *save_list,
 
3736
                                     vector<COND_CMP>& save_list,
3737
3737
                                     Item *and_father,
3738
3738
                                     Item *cond,
3739
3739
                                     Item *field,
3741
3741
{
3742
3742
  if (cond->type() == Item::COND_ITEM)
3743
3743
  {
3744
 
    bool and_level= ((Item_cond*) cond)->functype() ==
3745
 
      Item_func::COND_AND_FUNC;
 
3744
    bool and_level= ((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC;
3746
3745
    List_iterator<Item> li(*((Item_cond*) cond)->argument_list());
3747
3746
    Item *item;
3748
3747
    while ((item=li++))
3749
 
      change_cond_ref_to_const(session, save_list,and_level ? cond : item, item, field, value);
 
3748
      change_cond_ref_to_const(session, save_list, and_level ? cond : item, item, field, value);
3750
3749
    return;
3751
3750
  }
3752
3751
  if (cond->eq_cmp_result() == Item::COND_OK)
3776
3775
          ! left_item->const_item())
3777
3776
      {
3778
3777
        cond->marker=1;
3779
 
        COND_CMP *tmp2;
3780
 
        if ((tmp2=new COND_CMP(and_father,func)))
3781
 
          save_list->push_back(tmp2);
 
3778
        save_list.push_back( COND_CMP(and_father, func) );
3782
3779
      }
3783
3780
      func->set_cmp_func();
3784
3781
    }
3804
3801
        args[0]= args[1];                       // For easy check
3805
3802
        session->change_item_tree(args + 1, value);
3806
3803
        cond->marker=1;
3807
 
        COND_CMP *tmp2;
3808
 
        if ((tmp2=new COND_CMP(and_father,func)))
3809
 
          save_list->push_back(tmp2);
 
3804
        save_list.push_back( COND_CMP(and_father, func) );
3810
3805
      }
3811
3806
      func->set_cmp_func();
3812
3807
    }
3845
3840
}
3846
3841
 
3847
3842
static void propagate_cond_constants(Session *session, 
3848
 
                                     I_List<COND_CMP> *save_list, 
 
3843
                                     vector<COND_CMP>& save_list, 
3849
3844
                                     COND *and_father, 
3850
3845
                                     COND *cond)
3851
3846
{
3852
3847
  if (cond->type() == Item::COND_ITEM)
3853
3848
  {
3854
 
    bool and_level= ((Item_cond*) cond)->functype() ==
3855
 
      Item_func::COND_AND_FUNC;
 
3849
    bool and_level= ((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC;
3856
3850
    List_iterator_fast<Item> li(*((Item_cond*) cond)->argument_list());
3857
3851
    Item *item;
3858
 
    I_List<COND_CMP> save;
 
3852
    vector<COND_CMP> save;
3859
3853
    while ((item=li++))
3860
3854
    {
3861
 
      propagate_cond_constants(session, &save,and_level ? cond : item, item);
 
3855
      propagate_cond_constants(session, save, and_level ? cond : item, item);
3862
3856
    }
3863
3857
    if (and_level)
3864
 
    {                                           // Handle other found items
3865
 
      I_List_iterator<COND_CMP> cond_itr(save);
3866
 
      COND_CMP *cond_cmp;
3867
 
      while ((cond_cmp=cond_itr++))
 
3858
    {
 
3859
      // Handle other found items
 
3860
      for (vector<COND_CMP>::iterator iter= save.begin(); iter != save.end(); ++iter)
3868
3861
      {
3869
 
        Item **args= cond_cmp->cmp_func->arguments();
 
3862
        Item **args= iter->cmp_func->arguments();
3870
3863
        if (!args[0]->const_item())
3871
 
          change_cond_ref_to_const(session, &save,cond_cmp->and_level,
3872
 
                                   cond_cmp->and_level, args[0], args[1]);
 
3864
        {
 
3865
          change_cond_ref_to_const( session, save, iter->and_level,
 
3866
                                    iter->and_level, args[0], args[1] );
 
3867
        }
3873
3868
      }
3874
3869
    }
3875
3870
  }
4090
4085
                             &join->cond_equal);
4091
4086
 
4092
4087
    /* change field = field to field = const for each found field = const */
4093
 
    propagate_cond_constants(session, (I_List<COND_CMP> *) 0, conds, conds);
 
4088
    vector<COND_CMP> temp;
 
4089
    propagate_cond_constants(session, temp, conds, conds);
4094
4090
    /*
4095
4091
      Remove all instances of item == item
4096
4092
      Remove all and-levels where CONST item != CONST item