1237.13.44
by Padraig O'Sullivan
Moved the SEL_TREE and SEL_IMERGE classes out into their own header and implementation files. |
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) 2008-2009 Sun Microsystems, Inc.
|
1237.13.44
by Padraig O'Sullivan
Moved the SEL_TREE and SEL_IMERGE classes out into their own header and implementation files. |
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 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
20 |
#include <config.h> |
1237.13.44
by Padraig O'Sullivan
Moved the SEL_TREE and SEL_IMERGE classes out into their own header and implementation files. |
21 |
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
22 |
#include <drizzled/sql_base.h> |
23 |
#include <drizzled/sql_select.h> |
|
24 |
#include <drizzled/memory/sql_alloc.h> |
|
25 |
#include <drizzled/optimizer/range.h> |
|
26 |
#include <drizzled/optimizer/range_param.h> |
|
27 |
#include <drizzled/optimizer/sel_arg.h> |
|
28 |
#include <drizzled/optimizer/sel_tree.h> |
|
29 |
#include <drizzled/optimizer/sel_imerge.h> |
|
1237.13.44
by Padraig O'Sullivan
Moved the SEL_TREE and SEL_IMERGE classes out into their own header and implementation files. |
30 |
|
31 |
using namespace std; |
|
32 |
using namespace drizzled; |
|
33 |
||
34 |
optimizer::SEL_IMERGE::SEL_IMERGE() |
|
35 |
:
|
|
36 |
trees(&trees_prealloced[0]), |
|
37 |
trees_next(trees), |
|
38 |
trees_end(trees + PREALLOCED_TREES) |
|
39 |
{}
|
|
40 |
||
41 |
||
2318.6.46
by Olaf van der Spek
Refactor |
42 |
void optimizer::SEL_IMERGE::or_sel_tree(optimizer::RangeParameter *param, optimizer::SEL_TREE *tree) |
1237.13.44
by Padraig O'Sullivan
Moved the SEL_TREE and SEL_IMERGE classes out into their own header and implementation files. |
43 |
{
|
44 |
if (trees_next == trees_end) |
|
45 |
{
|
|
2318.6.72
by Olaf van der Spek
Refactor |
46 |
uint32_t old_elements= trees_end - trees; |
47 |
optimizer::SEL_TREE** new_trees= new (*param->mem_root) optimizer::SEL_TREE*[2 * old_elements]; |
|
48 |
memcpy(new_trees, trees, sizeof(optimizer::SEL_TREE**) * old_elements); |
|
1237.13.44
by Padraig O'Sullivan
Moved the SEL_TREE and SEL_IMERGE classes out into their own header and implementation files. |
49 |
trees= new_trees; |
50 |
trees_next= trees + old_elements; |
|
2318.6.72
by Olaf van der Spek
Refactor |
51 |
trees_end= trees + 2 * old_elements; |
1237.13.44
by Padraig O'Sullivan
Moved the SEL_TREE and SEL_IMERGE classes out into their own header and implementation files. |
52 |
}
|
53 |
*(trees_next++)= tree; |
|
54 |
}
|
|
55 |
||
56 |
||
2318.6.48
by Olaf van der Spek
Refactor |
57 |
int optimizer::SEL_IMERGE::or_sel_tree_with_checks(optimizer::RangeParameter& param, optimizer::SEL_TREE& new_tree) |
1237.13.44
by Padraig O'Sullivan
Moved the SEL_TREE and SEL_IMERGE classes out into their own header and implementation files. |
58 |
{
|
2318.6.46
by Olaf van der Spek
Refactor |
59 |
for (optimizer::SEL_TREE** tree = trees; tree != trees_next; tree++) |
1237.13.44
by Padraig O'Sullivan
Moved the SEL_TREE and SEL_IMERGE classes out into their own header and implementation files. |
60 |
{
|
2318.6.48
by Olaf van der Spek
Refactor |
61 |
if (sel_trees_can_be_ored(**tree, new_tree, param)) |
1237.13.44
by Padraig O'Sullivan
Moved the SEL_TREE and SEL_IMERGE classes out into their own header and implementation files. |
62 |
{
|
2318.6.48
by Olaf van der Spek
Refactor |
63 |
*tree = tree_or(¶m, *tree, &new_tree); |
1237.13.44
by Padraig O'Sullivan
Moved the SEL_TREE and SEL_IMERGE classes out into their own header and implementation files. |
64 |
if (!*tree) |
65 |
return 1; |
|
2318.6.48
by Olaf van der Spek
Refactor |
66 |
if (((*tree)->type == SEL_TREE::MAYBE) || |
67 |
((*tree)->type == SEL_TREE::ALWAYS)) |
|
1237.13.44
by Padraig O'Sullivan
Moved the SEL_TREE and SEL_IMERGE classes out into their own header and implementation files. |
68 |
return 1; |
69 |
/* optimizer::SEL_TREE::IMPOSSIBLE is impossible here */
|
|
70 |
return 0; |
|
71 |
}
|
|
72 |
}
|
|
73 |
||
74 |
/* New tree cannot be combined with any of existing trees. */
|
|
2318.6.48
by Olaf van der Spek
Refactor |
75 |
or_sel_tree(¶m, &new_tree); |
2318.6.46
by Olaf van der Spek
Refactor |
76 |
return 0; |
1237.13.44
by Padraig O'Sullivan
Moved the SEL_TREE and SEL_IMERGE classes out into their own header and implementation files. |
77 |
}
|
78 |
||
79 |
||
2318.6.49
by Olaf van der Spek
Refactor |
80 |
int optimizer::SEL_IMERGE::or_sel_imerge_with_checks(RangeParameter& param, SEL_IMERGE& imerge) |
1237.13.44
by Padraig O'Sullivan
Moved the SEL_TREE and SEL_IMERGE classes out into their own header and implementation files. |
81 |
{
|
2318.6.49
by Olaf van der Spek
Refactor |
82 |
for (SEL_TREE** tree= imerge.trees; tree != imerge.trees_next; tree++) |
1237.13.44
by Padraig O'Sullivan
Moved the SEL_TREE and SEL_IMERGE classes out into their own header and implementation files. |
83 |
{
|
2318.6.49
by Olaf van der Spek
Refactor |
84 |
if (or_sel_tree_with_checks(param, **tree)) |
1237.13.44
by Padraig O'Sullivan
Moved the SEL_TREE and SEL_IMERGE classes out into their own header and implementation files. |
85 |
return 1; |
86 |
}
|
|
87 |
return 0; |
|
88 |
}
|
|
89 |