~posulliv/drizzle/memcached_applier

« back to all changes in this revision

Viewing changes to drizzled/sql_select.cc

Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
2091
2091
  return cond;
2092
2092
}
2093
2093
 
2094
 
/*
2095
 
  Try to extract and push the index condition
2096
 
 
2097
 
  SYNOPSIS
2098
 
    push_index_cond()
2099
 
      tab            A join tab that has tab->table->file and its condition
2100
 
                     in tab->select_cond
2101
 
      keyno          Index for which extract and push the condition
2102
 
      other_tbls_ok  true <=> Fields of other non-const tables are allowed
2103
 
 
2104
 
  DESCRIPTION
2105
 
    Try to extract and push the index condition down to table handler
2106
 
*/
2107
 
void push_index_cond(JoinTable *tab, uint32_t keyno, bool other_tbls_ok)
2108
 
{
2109
 
  Item *idx_cond;
2110
 
  if (tab->table->file->index_flags(keyno, 0, 1) & HA_DO_INDEX_COND_PUSHDOWN &&
2111
 
      tab->join->session->variables.engine_condition_pushdown)
2112
 
  {
2113
 
    idx_cond= make_cond_for_index(tab->select_cond, tab->table, keyno,
2114
 
                                  other_tbls_ok);
2115
 
 
2116
 
    if (idx_cond)
2117
 
    {
2118
 
      tab->pre_idx_push_select_cond= tab->select_cond;
2119
 
      Item *idx_remainder_cond= tab->table->file->idx_cond_push(keyno, idx_cond);
2120
 
 
2121
 
      /*
2122
 
        Disable eq_ref's "lookup cache" if we've pushed down an index
2123
 
        condition.
2124
 
        TODO: This check happens to work on current ICP implementations, but
2125
 
        there may exist a compliant implementation that will not work
2126
 
        correctly with it. Sort this out when we stabilize the condition
2127
 
        pushdown APIs.
2128
 
      */
2129
 
      if (idx_remainder_cond != idx_cond)
2130
 
        tab->ref.disable_cache= true;
2131
 
 
2132
 
      Item *row_cond= make_cond_remainder(tab->select_cond, true);
2133
 
 
2134
 
      if (row_cond)
2135
 
      {
2136
 
        if (!idx_remainder_cond)
2137
 
          tab->select_cond= row_cond;
2138
 
        else
2139
 
        {
2140
 
          tab->select_cond= new Item_cond_and(row_cond, idx_remainder_cond);
2141
 
          tab->select_cond->quick_fix_field();
2142
 
          ((Item_cond_and*)tab->select_cond)->used_tables_cache=
2143
 
            row_cond->used_tables() | idx_remainder_cond->used_tables();
2144
 
        }
2145
 
      }
2146
 
      else
2147
 
        tab->select_cond= idx_remainder_cond;
2148
 
      if (tab->select)
2149
 
      {
2150
 
        tab->select->cond= tab->select_cond;
2151
 
      }
2152
 
    }
2153
 
  }
2154
 
  return;
2155
 
}
2156
 
 
2157
2094
/**
2158
2095
  cleanup JoinTable.
2159
2096
*/
5910
5847
   - If no index, create with filesort() an index file that can be used to
5911
5848
     retrieve rows in order (should be done with 'read_record').
5912
5849
     The sorted data is stored in tab->table and will be freed when calling
5913
 
     free_io_cache(tab->table).
 
5850
     tab->table->free_io_cache().
5914
5851
 
5915
5852
  RETURN VALUES
5916
5853
    0           ok
7569
7506
        else if (tab->select && tab->select->quick)
7570
7507
          keyno = tab->select->quick->index;
7571
7508
 
7572
 
        if (keyno != MAX_KEY && keyno == table->file->pushed_idx_cond_keyno &&
7573
 
            table->file->pushed_idx_cond)
7574
 
          extra.append(STRING_WITH_LEN("; Using index condition"));
7575
 
 
7576
7509
        if (quick_type == QUICK_SELECT_I::QS_TYPE_ROR_UNION ||
7577
7510
            quick_type == QUICK_SELECT_I::QS_TYPE_ROR_INTERSECT ||
7578
7511
            quick_type == QUICK_SELECT_I::QS_TYPE_INDEX_MERGE)
7609
7542
          }
7610
7543
          else if (tab->select->cond)
7611
7544
          {
7612
 
            const COND *pushed_cond= tab->table->file->pushed_cond;
7613
 
 
7614
 
            if (session->variables.engine_condition_pushdown && pushed_cond)
7615
 
            {
7616
 
              extra.append(STRING_WITH_LEN("; Using where with pushed "
7617
 
                                           "condition"));
7618
 
              if (session->lex->describe & DESCRIBE_EXTENDED)
7619
 
              {
7620
 
                extra.append(STRING_WITH_LEN(": "));
7621
 
                ((COND *)pushed_cond)->print(&extra, QT_ORDINARY);
7622
 
              }
7623
 
            }
7624
 
            else
7625
 
              extra.append(STRING_WITH_LEN("; Using where"));
 
7545
            extra.append(STRING_WITH_LEN("; Using where"));
7626
7546
          }
7627
7547
        }
7628
7548
        if (key_read)