1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2010 Padraig O'Sullivan
|
|
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 |
||
1475.1.2
by Padraig O'Sullivan
Fixed various compiler errors in access method classes due to forgetting includes. |
21 |
#include "config.h" |
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
22 |
#include "drizzled/session.h" |
23 |
#include "drizzled/join_table.h" |
|
1475.1.2
by Padraig O'Sullivan
Fixed various compiler errors in access method classes due to forgetting includes. |
24 |
#include "drizzled/table.h" |
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
25 |
#include "drizzled/sql_select.h" |
1475.1.2
by Padraig O'Sullivan
Fixed various compiler errors in access method classes due to forgetting includes. |
26 |
#include "drizzled/internal/my_sys.h" |
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
27 |
#include "drizzled/optimizer/access_method/scan.h" |
28 |
||
29 |
using namespace drizzled; |
|
30 |
||
1541.1.1
by Brian Aker
JOIN -> Join rename |
31 |
static uint32_t make_join_orderinfo(Join *join); |
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
32 |
|
33 |
bool optimizer::Scan::getStats(Table *table, |
|
34 |
JoinTable *join_tab) |
|
35 |
{
|
|
1541.1.1
by Brian Aker
JOIN -> Join rename |
36 |
Join *join= join_tab->join; |
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
37 |
bool statistics= test(! (join->select_options & SELECT_DESCRIBE)); |
38 |
uint64_t options= (join->select_options & |
|
39 |
(SELECT_DESCRIBE | SELECT_NO_JOIN_CACHE)) | |
|
40 |
(0); |
|
41 |
uint32_t no_jbuf_after= make_join_orderinfo(join); |
|
42 |
uint32_t index= join_tab - join->join_tab; |
|
43 |
||
44 |
/*
|
|
45 |
* If previous table use cache
|
|
46 |
* If the incoming data set is already sorted don't use cache.
|
|
47 |
*/
|
|
48 |
table->status= STATUS_NO_RECORD; |
|
49 |
||
50 |
if (index != join->const_tables && |
|
51 |
! (options & SELECT_NO_JOIN_CACHE) && |
|
52 |
join_tab->use_quick != 2 && |
|
53 |
! join_tab->first_inner && |
|
54 |
index <= no_jbuf_after && |
|
55 |
! join_tab->insideout_match_tab) |
|
56 |
{
|
|
57 |
if ((options & SELECT_DESCRIBE) || |
|
58 |
! join_init_cache(join->session, |
|
59 |
join->join_tab + join->const_tables, |
|
60 |
index - join->const_tables)) |
|
61 |
{
|
|
62 |
join_tab[-1].next_select= sub_select_cache; /* Patch previous */ |
|
63 |
}
|
|
64 |
}
|
|
65 |
||
66 |
/* These init changes read_record */
|
|
67 |
if (join_tab->use_quick == 2) |
|
68 |
{
|
|
69 |
join->session->server_status|= SERVER_QUERY_NO_GOOD_INDEX_USED; |
|
70 |
join_tab->read_first_record= join_init_quick_read_record; |
|
71 |
if (statistics) |
|
72 |
{
|
|
1689.5.1
by Joseph Daly
remove increment calls |
73 |
join->session->status_var.select_range_check_count++; |
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
74 |
}
|
75 |
}
|
|
76 |
else
|
|
77 |
{
|
|
78 |
join_tab->read_first_record= join_init_read_record; |
|
79 |
if (index == join->const_tables) |
|
80 |
{
|
|
81 |
if (join_tab->select && join_tab->select->quick) |
|
82 |
{
|
|
83 |
if (statistics) |
|
84 |
{
|
|
1689.5.1
by Joseph Daly
remove increment calls |
85 |
join->session->status_var.select_range_count++; |
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
86 |
}
|
87 |
}
|
|
88 |
else
|
|
89 |
{
|
|
90 |
join->session->server_status|= SERVER_QUERY_NO_INDEX_USED; |
|
91 |
if (statistics) |
|
92 |
{
|
|
1689.5.1
by Joseph Daly
remove increment calls |
93 |
join->session->status_var.select_scan_count++; |
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
94 |
}
|
95 |
}
|
|
96 |
}
|
|
97 |
else
|
|
98 |
{
|
|
99 |
if (join_tab->select && join_tab->select->quick) |
|
100 |
{
|
|
101 |
if (statistics) |
|
102 |
{
|
|
1689.5.1
by Joseph Daly
remove increment calls |
103 |
join->session->status_var.select_full_range_join_count++; |
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
104 |
}
|
105 |
}
|
|
106 |
else
|
|
107 |
{
|
|
108 |
join->session->server_status|= SERVER_QUERY_NO_INDEX_USED; |
|
109 |
if (statistics) |
|
110 |
{
|
|
1689.5.1
by Joseph Daly
remove increment calls |
111 |
join->session->status_var.select_full_join_count++; |
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
112 |
}
|
113 |
}
|
|
114 |
}
|
|
115 |
if (! table->no_keyread) |
|
116 |
{
|
|
117 |
if (join_tab->select && |
|
118 |
join_tab->select->quick && |
|
119 |
join_tab->select->quick->index != MAX_KEY && //not index_merge |
|
120 |
table->covering_keys.test(join_tab->select->quick->index)) |
|
121 |
{
|
|
122 |
table->key_read= 1; |
|
1475.1.2
by Padraig O'Sullivan
Fixed various compiler errors in access method classes due to forgetting includes. |
123 |
table->cursor->extra(HA_EXTRA_KEYREAD); |
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
124 |
}
|
125 |
else if (! table->covering_keys.none() && |
|
126 |
! (join_tab->select && join_tab->select->quick)) |
|
127 |
{ // Only read index tree |
|
128 |
if (! join_tab->insideout_match_tab) |
|
129 |
{
|
|
130 |
/*
|
|
131 |
See bug #26447: "Using the clustered index for a table scan
|
|
132 |
is always faster than using a secondary index".
|
|
133 |
*/
|
|
1618
by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have |
134 |
if (table->getShare()->hasPrimaryKey() && |
1475.1.2
by Padraig O'Sullivan
Fixed various compiler errors in access method classes due to forgetting includes. |
135 |
table->cursor->primary_key_is_clustered()) |
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
136 |
{
|
1618
by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have |
137 |
join_tab->index= table->getShare()->getPrimaryKey(); |
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
138 |
}
|
139 |
else
|
|
140 |
{
|
|
141 |
join_tab->index= table->find_shortest_key(&table->covering_keys); |
|
142 |
}
|
|
143 |
}
|
|
144 |
join_tab->read_first_record= join_read_first; |
|
145 |
join_tab->type= AM_NEXT; // Read with index_first / index_next |
|
146 |
}
|
|
147 |
}
|
|
148 |
}
|
|
1618
by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have |
149 |
|
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
150 |
return false; |
151 |
}
|
|
152 |
||
153 |
/**
|
|
154 |
Determine if the set is already ordered for order_st BY, so it can
|
|
155 |
disable join cache because it will change the ordering of the results.
|
|
156 |
Code handles sort table that is at any location (not only first after
|
|
157 |
the const tables) despite the fact that it's currently prohibited.
|
|
158 |
We must disable join cache if the first non-const table alone is
|
|
159 |
ordered. If there is a temp table the ordering is done as a last
|
|
160 |
operation and doesn't prevent join cache usage.
|
|
161 |
*/
|
|
1541.1.1
by Brian Aker
JOIN -> Join rename |
162 |
static uint32_t make_join_orderinfo(Join *join) |
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
163 |
{
|
1475.1.2
by Padraig O'Sullivan
Fixed various compiler errors in access method classes due to forgetting includes. |
164 |
uint32_t i= 0; |
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
165 |
if (join->need_tmp) |
1475.1.2
by Padraig O'Sullivan
Fixed various compiler errors in access method classes due to forgetting includes. |
166 |
{
|
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
167 |
return join->tables; |
1475.1.2
by Padraig O'Sullivan
Fixed various compiler errors in access method classes due to forgetting includes. |
168 |
}
|
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
169 |
|
1475.1.2
by Padraig O'Sullivan
Fixed various compiler errors in access method classes due to forgetting includes. |
170 |
for (i= join->const_tables ; i < join->tables ; i++) |
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
171 |
{
|
1475.1.2
by Padraig O'Sullivan
Fixed various compiler errors in access method classes due to forgetting includes. |
172 |
JoinTable *tab= join->join_tab + i; |
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
173 |
Table *table= tab->table; |
174 |
if ((table == join->sort_by_table && |
|
1475.1.2
by Padraig O'Sullivan
Fixed various compiler errors in access method classes due to forgetting includes. |
175 |
(! join->order || join->skip_sort_order)) || |
1475.1.1
by Padraig O'Sullivan
Added interface and various implementations to abstract out the concept of an access method. Also added a factory class for creating an instance of an access method. |
176 |
(join->sort_by_table == (Table *) 1 && i != join->const_tables)) |
177 |
{
|
|
178 |
break; |
|
179 |
}
|
|
180 |
}
|
|
181 |
return i; |
|
182 |
}
|