Drizzled Public API Documentation

sel_imerge.h

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #pragma once
00021 
00022 #include <drizzled/memory/sql_alloc.h>
00023 
00024 namespace drizzled
00025 {
00026 
00027 namespace optimizer
00028 {
00029 
00030 class RangeParameter;
00031 class SEL_TREE;
00032 class SEL_ARG;
00033 
00034 /*
00035   SEL_IMERGE is a list of possible ways to do index merge, i.e. it is
00036   a condition in the following form:
00037    (t_1||t_2||...||t_N) && (next)
00038 
00039   where all t_i are optimizer::SEL_TREEs, next is another SEL_IMERGE and no pair
00040   (t_i,t_j) contains SEL_ARGS for the same index.
00041 
00042   optimizer::SEL_TREE contained in SEL_IMERGE always has merges=NULL.
00043 
00044   This class relies on memory manager to do the cleanup.
00045 */
00046 class SEL_IMERGE : public memory::SqlAlloc
00047 {
00048   enum { PREALLOCED_TREES= 10};
00049 public:
00050   SEL_TREE *trees_prealloced[PREALLOCED_TREES];
00051   SEL_TREE **trees;             /* trees used to do index_merge   */
00052   SEL_TREE **trees_next;        /* last of these trees            */
00053   SEL_TREE **trees_end;         /* end of allocated space         */
00054 
00055   SEL_ARG  ***best_keys;        /* best keys to read in optimizer::SEL_TREEs */
00056 
00057   SEL_IMERGE();
00058 
00059   /*
00060      Add optimizer::SEL_TREE to this index_merge without any checks,
00061 
00062      NOTES
00063      This function implements the following:
00064      (x_1||...||x_N) || t = (x_1||...||x_N||t), where x_i, t are optimizer::SEL_TREEs
00065 
00066      RETURN
00067      0 - OK
00068      -1 - Out of memory.
00069    */
00070   int or_sel_tree(RangeParameter *param, SEL_TREE *tree);
00071 
00072   /*
00073      Perform OR operation on this SEL_IMERGE and supplied optimizer::SEL_TREE new_tree,
00074      combining new_tree with one of the trees in this SEL_IMERGE if they both
00075      have SEL_ARGs for the same key.
00076 
00077      SYNOPSIS
00078      or_sel_tree_with_checks()
00079      param    Parameter from SqlSelect::test_quick_select
00080      new_tree optimizer::SEL_TREE with type KEY or KEY_SMALLER.
00081 
00082      NOTES
00083      This does the following:
00084      (t_1||...||t_k)||new_tree =
00085      either
00086      = (t_1||...||t_k||new_tree)
00087      or
00088      = (t_1||....||(t_j|| new_tree)||...||t_k),
00089 
00090      where t_i, y are optimizer::SEL_TREEs.
00091      new_tree is combined with the first t_j it has a SEL_ARG on common
00092      key with. As a consequence of this, choice of keys to do index_merge
00093      read may depend on the order of conditions in WHERE part of the query.
00094 
00095      RETURN
00096      0  OK
00097      1  One of the trees was combined with new_tree to optimizer::SEL_TREE::ALWAYS,
00098      and (*this) should be discarded.
00099      -1  An error occurred.
00100    */
00101   int or_sel_tree_with_checks(optimizer::RangeParameter *param, optimizer::SEL_TREE *new_tree);
00102 
00103   /*
00104      Perform OR operation on this index_merge and supplied index_merge list.
00105 
00106      RETURN
00107      0 - OK
00108      1 - One of conditions in result is always true and this SEL_IMERGE
00109      should be discarded.
00110      -1 - An error occurred
00111    */
00112   int or_sel_imerge_with_checks(optimizer::RangeParameter *param, SEL_IMERGE* imerge);
00113 
00114 };
00115 
00116 
00117 } /* namespace optimizer */
00118 
00119 } /* namespace drizzled */
00120