~drizzle-trunk/drizzle/development

1108.6.30 by Padraig O'Sullivan
Forgot to add the new sub-dir I created for my last commit.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2009 Sun Microsystems, Inc.
1108.6.30 by Padraig O'Sullivan
Forgot to add the new sub-dir I created for my last commit.
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; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
20
#pragma once
1108.6.30 by Padraig O'Sullivan
Forgot to add the new sub-dir I created for my last commit.
21
2154.2.9 by Brian Aker
Merge in session up and out of sql_select.h
22
#include <drizzled/join_table.h>
1108.6.30 by Padraig O'Sullivan
Forgot to add the new sub-dir I created for my last commit.
23
24
namespace drizzled
25
{
26
namespace optimizer
27
{
28
29
/**
30
 * Information about a position of table within a join order. Used in join
31
 * optimization.
32
 */
33
class Position
34
{
35
public:
36
37
  Position()
38
    :
39
      records_read(0),
40
      read_time(0),
41
      table(NULL),
42
      key(NULL),
43
      ref_depend_map(0)
44
  {}
45
46
  Position(double in_records_read,
47
           double in_read_time,
48
           JoinTable *in_table,
49
           KeyUse *in_key,
50
           table_map in_ref_depend_map)
51
    :
52
      records_read(in_records_read),
53
      read_time(in_read_time),
54
      table(in_table),
55
      key(in_key),
56
      ref_depend_map(in_ref_depend_map)
57
  {}
58
1108.6.52 by Padraig O'Sullivan
Added a copy constructor and assignment operator to the Position class.
59
  Position(const Position &rhs)
60
    :
61
      records_read(rhs.records_read),
62
      read_time(rhs.read_time),
63
      table(rhs.table),
64
      key(rhs.key),
65
      ref_depend_map(rhs.ref_depend_map)
66
  {}
67
68
  Position &operator=(const Position &rhs)
69
  {
70
    if (this == &rhs)
71
    {
72
      return *this;
73
    }
74
    records_read= rhs.records_read;
75
    read_time= rhs.read_time;
76
    table= rhs.table;
77
    key= rhs.key;
78
    ref_depend_map= rhs.ref_depend_map;
79
    return *this;
80
  }
81
1108.6.30 by Padraig O'Sullivan
Forgot to add the new sub-dir I created for my last commit.
82
  /**
83
   * Determine whether the table this particular position is representing in
84
   * the query plan is a const table or not. A constant table is defined as
85
   * (taken from the MySQL optimizer internals document on MySQL forge):
86
   *
87
   * 1) A table with zero rows, or with only one row
88
   * 2) A table expression that is restricted with a WHERE condition
89
   *
90
   * Based on the definition above, when records_read is set to 1.0 in the
91
   * Position class, it infers that this position in the partial plan
92
   * represents a const table.
93
   *
94
   * @return true if this position represents a const table; false otherwise
95
   */
96
  bool isConstTable() const
97
  {
98
    return (records_read < 2.0);
99
  }
100
101
  double getFanout() const
102
  {
103
    return records_read;
104
  }
105
106
  void setFanout(double in_records_read)
107
  {
108
    records_read= in_records_read;
109
  }
110
111
  double getCost() const
112
  {
113
    return read_time;
114
  }
115
116
  JoinTable *getJoinTable()
117
  {
118
    return table;
119
  }
120
121
  /**
122
   * Check to see if the table attached to the JoinTable for this position
123
   * has an index that can produce an ordering. 
124
   *
125
   * @return true if the table attached to the JoinTable for this position
126
   * does not have an index that can produce an ordering; false otherwise
127
   */
128
  bool hasTableForSorting(Table *cmp_table) const
129
  {
130
    return (cmp_table != table->table);
131
  }
132
2154.2.15 by Brian Aker
Merge in optimizer pieces.
133
  bool examinePosition(table_map found_ref);
1108.6.30 by Padraig O'Sullivan
Forgot to add the new sub-dir I created for my last commit.
134
135
  KeyUse *getKeyUse()
136
  {
137
    return key;
138
  }
139
2318.8.8 by Olaf van der Spek
Refactor Scoreboard
140
  table_map getRefDependMap() const
1108.6.30 by Padraig O'Sullivan
Forgot to add the new sub-dir I created for my last commit.
141
  {
142
    return ref_depend_map;
143
  }
144
145
  void clearRefDependMap()
146
  {
147
    ref_depend_map= 0;
148
  }
149
150
private:
151
152
  /**
153
    The "fanout": number of output rows that will be produced (after
154
    pushed down selection condition is applied) per each row combination of
155
    previous tables. The value is an in-precise estimate.
156
  */
157
  double records_read;
158
159
  /**
160
    Cost accessing the table in course of the entire complete join execution,
161
    i.e. cost of one access method use (e.g. 'range' or 'ref' scan ) times
162
    number the access method will be invoked.
163
  */
164
  double read_time;
165
166
  JoinTable *table;
167
168
  /**
169
    NULL  -  'index' or 'range' or 'index_merge' or 'ALL' access is used.
170
    Other - [eq_]ref[_or_null] access is used. Pointer to {t.keypart1 = expr}
171
  */
172
  KeyUse *key;
173
174
  /** If ref-based access is used: bitmap of tables this table depends on  */
175
  table_map ref_depend_map;
176
177
};
178
179
} /* end namespace optimizer */
180
181
} /* end namespace drizzled */
182