~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/join_tab.h

  • Committer: Brian Aker
  • Date: 2009-06-01 04:09:48 UTC
  • mfrom: (1039.2.9 working)
  • Revision ID: brian@gaz-20090601040948-ke10l7ndpzd6oupw
Merge Jay.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008-2009 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 */
 
20
 
 
21
/**
 
22
 * @file
 
23
 *
 
24
 * Defines the JOIN_TAB class which is the primary class
 
25
 * used in the nested loops join implementation.
 
26
 */
 
27
 
 
28
#ifndef DRIZZLED_JOIN_TAB_H
 
29
#define DRIZZLED_JOIN_TAB_H
 
30
 
 
31
typedef struct st_join_table 
 
32
{
 
33
  st_join_table() {}                          /* Remove gcc warning */
 
34
  Table *table;
 
35
  KEYUSE *keyuse;                       /**< pointer to first used key */
 
36
  SQL_SELECT *select;
 
37
  COND *select_cond;
 
38
  QUICK_SELECT_I *quick;
 
39
  /*
 
40
    The value of select_cond before we've attempted to do Index Condition
 
41
    Pushdown. We may need to restore everything back if we first choose one
 
42
    index but then reconsider (see test_if_skip_sort_order() for such
 
43
    scenarios).
 
44
    NULL means no index condition pushdown was performed.
 
45
  */
 
46
  Item *pre_idx_push_select_cond;
 
47
  Item **on_expr_ref;   /**< pointer to the associated on expression   */
 
48
  COND_EQUAL *cond_equal;    /**< multiple equalities for the on expression */
 
49
  st_join_table *first_inner;   /**< first inner table for including outerjoin */
 
50
  bool found;         /**< true after all matches or null complement */
 
51
  bool not_null_compl;/**< true before null complement is added      */
 
52
  st_join_table *last_inner;    /**< last table table for embedding outer join */
 
53
  st_join_table *first_upper;  /**< first inner table for embedding outer join */
 
54
  st_join_table *first_unmatched; /**< used for optimization purposes only     */
 
55
 
 
56
  /* Special content for EXPLAIN 'Extra' column or NULL if none */
 
57
  const char *info;
 
58
  /*
 
59
    Bitmap of TAB_INFO_* bits that encodes special line for EXPLAIN 'Extra'
 
60
    column, or 0 if there is no info.
 
61
  */
 
62
  uint32_t packed_info;
 
63
 
 
64
  Read_record_func read_first_record;
 
65
  Next_select_func next_select;
 
66
  READ_RECORD   read_record;
 
67
  /*
 
68
    Currently the following two fields are used only for a [NOT] IN subquery
 
69
    if it is executed by an alternative full table scan when the left operand of
 
70
    the subquery predicate is evaluated to NULL.
 
71
  */
 
72
  Read_record_func save_read_first_record;/* to save read_first_record */
 
73
  int (*save_read_record) (READ_RECORD *);/* to save read_record.read_record */
 
74
  double worst_seeks;
 
75
  key_map       const_keys;                     /**< Keys with constant part */
 
76
  key_map       checked_keys;                   /**< Keys checked in find_best */
 
77
  key_map       needed_reg;
 
78
  key_map keys;                           /**< all keys with can be used */
 
79
 
 
80
  /* Either #rows in the table or 1 for const table.  */
 
81
  ha_rows       records;
 
82
  /*
 
83
    Number of records that will be scanned (yes scanned, not returned) by the
 
84
    best 'independent' access method, i.e. table scan or QUICK_*_SELECT)
 
85
  */
 
86
  ha_rows found_records;
 
87
  /*
 
88
    Cost of accessing the table using "ALL" or range/index_merge access
 
89
    method (but not 'index' for some reason), i.e. this matches method which
 
90
    E(#records) is in found_records.
 
91
  */
 
92
  ha_rows read_time;
 
93
 
 
94
  table_map     dependent,key_dependent;
 
95
  uint32_t use_quick,index;
 
96
  uint32_t status;                              ///< Save status for cache
 
97
  uint          used_fields,used_fieldlength,used_blobs;
 
98
  enum join_type type;
 
99
  bool          cached_eq_ref_table,eq_ref_table,not_used_in_distinct;
 
100
  /* true <=> index-based access method must return records in order */
 
101
  bool          sorted;
 
102
  /*
 
103
    If it's not 0 the number stored this field indicates that the index
 
104
    scan has been chosen to access the table data and we expect to scan
 
105
    this number of rows for the table.
 
106
  */
 
107
  ha_rows limit;
 
108
  TABLE_REF     ref;
 
109
  JOIN_CACHE cache;
 
110
  JOIN *join;
 
111
  /** Bitmap of nested joins this table is part of */
 
112
 
 
113
  /* SemiJoinDuplicateElimination variables: */
 
114
  /*
 
115
    Embedding SJ-nest (may be not the direct parent), or NULL if none.
 
116
    This variable holds the result of table pullout.
 
117
  */
 
118
  TableList *emb_sj_nest;
 
119
 
 
120
  /* Variables for semi-join duplicate elimination */
 
121
  SJ_TMP_TABLE *flush_weedout_table;
 
122
  SJ_TMP_TABLE *check_weed_out_table;
 
123
  struct st_join_table *do_firstmatch;
 
124
 
 
125
  /*
 
126
     ptr  - this join tab should do an InsideOut scan. Points
 
127
            to the tab for which we'll need to check tab->found_match.
 
128
 
 
129
     NULL - Not an insideout scan.
 
130
  */
 
131
  struct st_join_table *insideout_match_tab;
 
132
  unsigned char *insideout_buf; // Buffer to save index tuple to be able to skip dups
 
133
 
 
134
  /* Used by InsideOut scan. Just set to true when have found a row. */
 
135
  bool found_match;
 
136
 
 
137
  enum {
 
138
    /* If set, the rowid of this table must be put into the temptable. */
 
139
    KEEP_ROWID=1,
 
140
    /*
 
141
      If set, one should call h->position() to obtain the rowid,
 
142
      otherwise, the rowid is assumed to already be in h->ref
 
143
      (this is because join caching and filesort() save the rowid and then
 
144
      put it back into h->ref)
 
145
    */
 
146
    CALL_POSITION=2
 
147
  };
 
148
  /* A set of flags from the above enum */
 
149
  int rowid_keep_flags;
 
150
 
 
151
  /* NestedOuterJoins: Bitmap of nested joins this table is part of */
 
152
  nested_join_map embedding_map;
 
153
 
 
154
  void cleanup();
 
155
  inline bool is_using_loose_index_scan()
 
156
  {
 
157
    return (select && select->quick &&
 
158
            (select->quick->get_type() ==
 
159
             QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX));
 
160
  }
 
161
} JOIN_TAB;
 
162
 
 
163
#endif /* DRIZZLED_JOIN_TAB_H */