~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/join.cc

  • Committer: Olaf van der Spek
  • Date: 2011-03-10 12:49:38 UTC
  • mto: This revision was merged to the branch mainline in revision 2233.
  • Revision ID: olafvdspek@gmail.com-20110310124938-gwhzx3pq8ueg682n
Session::lex()

Show diffs side-by-side

added added

removed removed

Lines of Context:
310
310
 
311
311
bool Join::is_top_level_join() const
312
312
{
313
 
  return (unit == &session->getLex()->unit && (unit->fake_select_lex == 0 ||
 
313
  return (unit == &session->lex().unit && (unit->fake_select_lex == 0 ||
314
314
                                          select_lex == unit->fake_select_lex));
315
315
}
316
316
 
351
351
  join_list= &select_lex->top_join_list;
352
352
  union_part= unit_arg->is_union();
353
353
 
354
 
  session->getLex()->current_select->is_item_list_lookup= 1;
 
354
  session->lex().current_select->is_item_list_lookup= 1;
355
355
  /*
356
356
    If we have already executed SELECT, then it have not sense to prevent
357
357
    its table from update (see unique_table())
392
392
 
393
393
  if (having)
394
394
  {
395
 
    nesting_map save_allow_sum_func= session->getLex()->allow_sum_func;
 
395
    nesting_map save_allow_sum_func= session->lex().allow_sum_func;
396
396
    session->setWhere("having clause");
397
 
    session->getLex()->allow_sum_func|= 1 << select_lex_arg->nest_level;
 
397
    session->lex().allow_sum_func|= 1 << select_lex_arg->nest_level;
398
398
    select_lex->having_fix_field= 1;
399
399
    bool having_fix_rc= (!having->fixed &&
400
400
       (having->fix_fields(session, &having) ||
402
402
    select_lex->having_fix_field= 0;
403
403
    if (having_fix_rc || session->is_error())
404
404
      return(-1);
405
 
    session->getLex()->allow_sum_func= save_allow_sum_func;
 
405
    session->lex().allow_sum_func= save_allow_sum_func;
406
406
  }
407
407
 
408
408
  {
452
452
            in_subs  &&                                                   // 1
453
453
            !select_lex->master_unit()->first_select()->next_select() &&  // 2
454
454
            select_lex->master_unit()->first_select()->leaf_tables &&     // 3
455
 
            session->getLex()->sql_command == SQLCOM_SELECT)                       // *
 
455
            session->lex().sql_command == SQLCOM_SELECT)                       // *
456
456
        {
457
457
          if (in_subs->is_top_level_item() &&                             // 4
458
458
              !in_subs->is_correlated &&                                  // 5
625
625
    select_limit= HA_POS_ERROR;
626
626
  do_send_rows = (unit->select_limit_cnt) ? 1 : 0;
627
627
  // Ignore errors of execution if option IGNORE present
628
 
  if (session->getLex()->ignore)
629
 
    session->getLex()->current_select->no_error= 1;
 
628
  if (session->lex().ignore)
 
629
    session->lex().current_select->no_error= 1;
630
630
 
631
631
#ifdef HAVE_REF_TO_FIELDS     // Not done yet
632
632
  /* Add HAVING to WHERE if possible */
726
726
        conjunctions.
727
727
        Preserve conditions for EXPLAIN.
728
728
      */
729
 
      if (conds && !(session->getLex()->describe & DESCRIBE_EXTENDED))
 
729
      if (conds && !(session->lex().describe & DESCRIBE_EXTENDED))
730
730
      {
731
731
        COND *table_independent_conds= make_cond_for_table(conds, PSEUDO_TABLE_BITS, 0, 0);
732
732
        conds= table_independent_conds;
761
761
      !(select_options & SELECT_DESCRIBE) &&
762
762
      (!conds ||
763
763
       !(conds->used_tables() & RAND_TABLE_BIT) ||
764
 
       select_lex->master_unit() == &session->getLex()->unit)) // upper level SELECT
 
764
       select_lex->master_unit() == &session->lex().unit)) // upper level SELECT
765
765
  {
766
766
    zero_result_cause= "no matching row in const table";
767
767
    goto setup_subq_exit;
821
821
 
822
822
  if (conds &&!outer_join && const_table_map != found_const_table_map &&
823
823
      (select_options & SELECT_DESCRIBE) &&
824
 
      select_lex->master_unit() == &session->getLex()->unit) // upper level SELECT
 
824
      select_lex->master_unit() == &session->lex().unit) // upper level SELECT
825
825
  {
826
826
    conds=new Item_int(0, 1);  // Always false
827
827
  }
1174
1174
    */
1175
1175
    ha_rows tmp_rows_limit= ((order == 0 || skip_sort_order) &&
1176
1176
                             !tmp_group &&
1177
 
                             !session->getLex()->current_select->with_sum_func) ?
 
1177
                             !session->lex().current_select->with_sum_func) ?
1178
1178
                            select_limit : HA_POS_ERROR;
1179
1179
 
1180
1180
    if (!(exec_tmp_table1=
1870
1870
    for a derived table which is always materialized.
1871
1871
    Otherwise we would not be able to print the query  correctly.
1872
1872
  */
1873
 
  if (items0 && (session->getLex()->describe & DESCRIBE_EXTENDED) && select_lex->linkage == DERIVED_TABLE_TYPE)
 
1873
  if (items0 && (session->lex().describe & DESCRIBE_EXTENDED) && select_lex->linkage == DERIVED_TABLE_TYPE)
1874
1874
    set_items_ref_array(items0);
1875
1875
 
1876
1876
  return;
2002
2002
    Optimization: if not EXPLAIN and we are done with the Join,
2003
2003
    free all tables.
2004
2004
  */
2005
 
  bool full= (select_lex->uncacheable.none() && ! session->getLex()->describe);
 
2005
  bool full= (select_lex->uncacheable.none() && ! session->lex().describe);
2006
2006
  bool can_unlock= full;
2007
2007
 
2008
2008
  cleanup(full);
2037
2037
  if (can_unlock && lock && session->lock &&
2038
2038
      !(select_options & SELECT_NO_UNLOCK) &&
2039
2039
      !select_lex->subquery_in_having &&
2040
 
      (select_lex == (session->getLex()->unit.fake_select_lex ?
2041
 
                      session->getLex()->unit.fake_select_lex : &session->getLex()->select_lex)))
 
2040
      (select_lex == (session->lex().unit.fake_select_lex ?
 
2041
                      session->lex().unit.fake_select_lex : &session->lex().select_lex)))
2042
2042
  {
2043
2043
    /*
2044
2044
      TODO: unlock tables even if the join isn't top level select in the
3526
3526
    i.e. they have subqueries, unions or call stored procedures.
3527
3527
    TODO: calculate a correct cost for a query with subqueries and UNIONs.
3528
3528
  */
3529
 
  if (join->session->getLex()->is_single_level_stmt())
 
3529
  if (join->session->lex().is_single_level_stmt())
3530
3530
    join->session->status_var.last_query_cost= join->best_read;
3531
3531
  return(false);
3532
3532
}
4720
4720
      if (join->tables > 1)
4721
4721
        cond->update_used_tables();             // Tablenr may have changed
4722
4722
      if (join->const_tables == join->tables &&
4723
 
          session->getLex()->current_select->master_unit() ==
4724
 
          &session->getLex()->unit)             // not upper level SELECT
 
4723
          session->lex().current_select->master_unit() ==
 
4724
          &session->lex().unit)         // not upper level SELECT
4725
4725
        join->const_table_map|=RAND_TABLE_BIT;
4726
4726
      {                                         // Check const tables
4727
4727
        COND *const_cond=
4799
4799
          join->full_join= 1;
4800
4800
      }
4801
4801
 
4802
 
      if (join->full_join and not session->getLex()->current_select->is_cross and not cond)
 
4802
      if (join->full_join and not session->lex().current_select->is_cross and not cond)
4803
4803
      {
4804
4804
        my_error(ER_CARTESIAN_JOIN_ATTEMPTED, MYF(0));
4805
4805
        return 1;
5649
5649
                               bool *hidden_group_fields)
5650
5650
{
5651
5651
  int res;
5652
 
  nesting_map save_allow_sum_func=session->getLex()->allow_sum_func ;
 
5652
  nesting_map save_allow_sum_func=session->lex().allow_sum_func ;
5653
5653
 
5654
 
  session->getLex()->allow_sum_func&= ~(1 << session->getLex()->current_select->nest_level);
 
5654
  session->lex().allow_sum_func&= ~(1 << session->lex().current_select->nest_level);
5655
5655
  res= session->setup_conds(tables, conds);
5656
5656
 
5657
 
  session->getLex()->allow_sum_func|= 1 << session->getLex()->current_select->nest_level;
 
5657
  session->lex().allow_sum_func|= 1 << session->lex().current_select->nest_level;
5658
5658
  res= res || setup_order(session, ref_pointer_array, tables, fields, all_fields,
5659
5659
                          order);
5660
 
  session->getLex()->allow_sum_func&= ~(1 << session->getLex()->current_select->nest_level);
 
5660
  session->lex().allow_sum_func&= ~(1 << session->lex().current_select->nest_level);
5661
5661
  res= res || setup_group(session, ref_pointer_array, tables, fields, all_fields,
5662
5662
                          group, hidden_group_fields);
5663
 
  session->getLex()->allow_sum_func= save_allow_sum_func;
 
5663
  session->lex().allow_sum_func= save_allow_sum_func;
5664
5664
  return(res);
5665
5665
}
5666
5666