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 namespace optimizer {
00026 
00027 /*
00028   SEL_IMERGE is a list of possible ways to do index merge, i.e. it is
00029   a condition in the following form:
00030    (t_1||t_2||...||t_N) && (next)
00031 
00032   where all t_i are optimizer::SEL_TREEs, next is another SEL_IMERGE and no pair
00033   (t_i,t_j) contains SEL_ARGS for the same index.
00034 
00035   optimizer::SEL_TREE contained in SEL_IMERGE always has merges=NULL.
00036 
00037   This class relies on memory manager to do the cleanup.
00038 */
00039 class SEL_IMERGE : public memory::SqlAlloc
00040 {
00041   enum { PREALLOCED_TREES= 10};
00042 public:
00043   SEL_TREE *trees_prealloced[PREALLOCED_TREES];
00044   SEL_TREE **trees;             /* trees used to do index_merge   */
00045   SEL_TREE **trees_next;        /* last of these trees            */
00046   SEL_TREE **trees_end;         /* end of allocated space         */
00047 
00048   SEL_ARG  ***best_keys;        /* best keys to read in optimizer::SEL_TREEs */
00049 
00050   SEL_IMERGE();
00051 
00052   /*
00053      Add optimizer::SEL_TREE to this index_merge without any checks,
00054 
00055      NOTES
00056      This function implements the following:
00057      (x_1||...||x_N) || t = (x_1||...||x_N||t), where x_i, t are optimizer::SEL_TREEs
00058 
00059      RETURN
00060      0 - OK
00061      -1 - Out of memory.
00062    */
00063   void or_sel_tree(RangeParameter *param, SEL_TREE *tree);
00064 
00065   /*
00066      Perform OR operation on this SEL_IMERGE and supplied optimizer::SEL_TREE new_tree,
00067      combining new_tree with one of the trees in this SEL_IMERGE if they both
00068      have SEL_ARGs for the same key.
00069 
00070      SYNOPSIS
00071      or_sel_tree_with_checks()
00072      param    Parameter from SqlSelect::test_quick_select
00073      new_tree optimizer::SEL_TREE with type KEY or KEY_SMALLER.
00074 
00075      NOTES
00076      This does the following:
00077      (t_1||...||t_k)||new_tree =
00078      either
00079      = (t_1||...||t_k||new_tree)
00080      or
00081      = (t_1||....||(t_j|| new_tree)||...||t_k),
00082 
00083      where t_i, y are optimizer::SEL_TREEs.
00084      new_tree is combined with the first t_j it has a SEL_ARG on common
00085      key with. As a consequence of this, choice of keys to do index_merge
00086      read may depend on the order of conditions in WHERE part of the query.
00087 
00088      RETURN
00089      0  OK
00090      1  One of the trees was combined with new_tree to optimizer::SEL_TREE::ALWAYS,
00091      and (*this) should be discarded.
00092      -1  An error occurred.
00093    */
00094   int or_sel_tree_with_checks(RangeParameter&, SEL_TREE&);
00095 
00096   /*
00097      Perform OR operation on this index_merge and supplied index_merge list.
00098 
00099      RETURN
00100      0 - OK
00101      1 - One of conditions in result is always true and this SEL_IMERGE
00102      should be discarded.
00103      -1 - An error occurred
00104    */
00105   int or_sel_imerge_with_checks(RangeParameter&, SEL_IMERGE&);
00106 
00107 };
00108 
00109 
00110 } /* namespace optimizer */
00111 
00112 } /* namespace drizzled */
00113