Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members

The top level query expression object. More...

#include <qExpr.h>

Inheritance diagram for ibis::qExpr:
ibis::compRange ibis::deprecatedJoin ibis::math::term ibis::qAllWords ibis::qAnyAny ibis::qAnyString ibis::qExists ibis::qKeyword ibis::qLike ibis::qRange ibis::qString

Classes

struct  TTN
 A data structure including a query expression and the list of table names mentioned in the expression. More...
 
struct  weight
 A functor to be used by the function reorder. More...
 

Public Types

enum  COMPARE {
  OP_UNDEFINED, OP_LT, OP_GT, OP_LE,
  OP_GE, OP_EQ
}
 Comparison operator supported in RANGE.
 
typedef std::vector< TTNtermTableList
 
enum  TYPE {
  LOGICAL_UNDEFINED, LOGICAL_NOT, LOGICAL_AND, LOGICAL_OR,
  LOGICAL_XOR, LOGICAL_MINUS, RANGE, DRANGE,
  STRING, ANYSTRING, KEYWORD, ALLWORDS,
  COMPRANGE, MATHTERM, DEPRECATEDJOIN, TOPK,
  EXISTS, ANYANY, LIKE, INTHOD,
  UINTHOD
}
 Definition of node types. More...
 

Public Member Functions

bool directEval () const
 Can the expression be directly evaluated?
 
virtual qExprdup () const
 !< Reorder the expressions tree. More...
 
void extractDeprecatedJoins (std::vector< const deprecatedJoin * > &) const
 Extract conjunctive terms of the deprecated joins.
 
qRangefindRange (const char *vname)
 Find the first range condition involving the named variable.
 
void getConjunctiveTerms (termTableList &) const
 Extract the top-level conjunctive terms. More...
 
qExpr *& getLeft ()
 Return a pointer to the left child. More...
 
const qExprgetLeft () const
 Return a const pointer to the left child.
 
qExpr *& getRight ()
 Return a pointer to the right child. More...
 
const qExprgetRight () const
 Return a const pointer to the right child.
 
virtual void getTableNames (std::set< std::string > &plist) const
 Identify the data partitions involved in the query expression. More...
 
TYPE getType () const
 Return the node type.
 
virtual bool isConstant () const
 Is this expression a constant? A constant remains the same not matter which row it is applied to. More...
 
virtual bool isSimple () const
 Is the expression simple? A simple expression contains only range conditions connected with logical operators. More...
 
bool isTerminal () const
 Is this expression a terminal node of an expression tree?
 
virtual uint32_t nItems () const
 Count the number of items in the query expression.
 
qExproperator= (const qExpr &rhs)
 Assignment operator.
 
virtual void print (std::ostream &) const
 Print out the node in the string form. More...
 
virtual void printFull (std::ostream &out) const
 Print out the full expression. More...
 
 qExpr ()
 Default constructor. It generates a node of undefined type.
 
 qExpr (TYPE op)
 Construct a node of specified type. Not for implicit type conversion.
 
 qExpr (TYPE op, qExpr *qe1, qExpr *qe2)
 Construct a full specified node. More...
 
 qExpr (const qExpr &qe)
 Copy Constructor. Deep copy.
 
double reorder (const weight &)
 After reordering, the lightest weight is one the left side of a group of commutable operators. More...
 
int separateSimple (ibis::qExpr *&simple, ibis::qExpr *&tail) const
 Separate an expression tree into two connected with an AND operator. More...
 
void setLeft (qExpr *expr)
 Change the left child. More...
 
void setRight (qExpr *expr)
 Change the right child. More...
 
void swap (qExpr &rhs)
 Swap the content. No exception expected.
 
virtual ~qExpr ()
 Destructor. More...
 

Static Public Member Functions

static std::string extractTableName (const char *)
 Extract the data partition name from the column name cn. More...
 
static void simplify (ibis::qExpr *&)
 Attempt to simplify the query expressions. More...
 
static void splitColumnName (const char *, std::string &, std::string &)
 Split the incoming name into data partition name and column name. More...
 

Protected Member Functions

void adjust ()
 Adjust the tree to favor the sequential evaluation order. More...
 

Protected Attributes

qExprleft
 The left child.
 
qExprright
 The right child.
 
TYPE type
 The type of node. More...
 

Detailed Description

The top level query expression object.

It encodes the logical operations between two child expressions, serving as the interior nodes of an expression tree. Leaf nodes are going to be derived later.

Member Enumeration Documentation

Definition of node types.

Logical operators are listed in the front and leaf node types are listed at the end.

Constructor & Destructor Documentation

ibis::qExpr::qExpr ( TYPE  op,
qExpr qe1,
qExpr qe2 
)
inline

Construct a full specified node.

The ownership of qe1 and qe2 is transferred to the newly created object. The destructor of this object will delete qe1 and qe2, the user shall not delete them directly or indirectly through the destruction of another object. This constructor is primarily used by the parsers that compose query expressions, where the final query expression tree is passed to the user. This design allows the user to take control of the final query expression without directly managing any of the lower level nodes in the expression tree.

virtual ibis::qExpr::~qExpr ( )
inlinevirtual

Destructor.

It recursively deletes the nodes of an expression tree. In other word, it owns the descendents it points to.

References left, and right.

Member Function Documentation

void ibis::qExpr::adjust ( )
protected

Adjust the tree to favor the sequential evaluation order.

Make the expression tree lean left.

References adjust(), and left.

Referenced by adjust().

virtual qExpr* ibis::qExpr::dup ( ) const
inlinevirtual
std::string ibis::qExpr::extractTableName ( const char *  cn)
static

Extract the data partition name from the column name cn.

It looks for the first period '.' in the column name. If a period is found, the characters before the period is returned as a string, otherwise, an empty string is returned.

Note
The data partition name will be outputed in lowercase characters.

Referenced by ibis::quaere::create(), ibis::qRange::getTableNames(), ibis::qString::getTableNames(), ibis::qAnyString::getTableNames(), ibis::qLike::getTableNames(), ibis::qKeyword::getTableNames(), ibis::qAllWords::getTableNames(), ibis::math::variable::getTableNames(), and ibis::qAnyAny::getTableNames().

void ibis::qExpr::getConjunctiveTerms ( termTableList &  ttl) const

Extract the top-level conjunctive terms.

If the top-most operator is not the AND operator, the whole expression tree is considered one term. Because this function may be called recursively, the argument ttl is not cleared by this function. The caller needs to make sure it is cleared on input.

Referenced by ibis::quaere::create().

qExpr*& ibis::qExpr::getLeft ( )
inline
qExpr*& ibis::qExpr::getRight ( )
inline
void ibis::qExpr::getTableNames ( std::set< std::string > &  plist) const
virtual

Identify the data partitions involved in the query expression.

Return the list of data partition names in a set.

It records a '*' for the variables without explicit partition names.

Reimplemented in ibis::qAnyAny, ibis::compRange, ibis::math::variable, ibis::qAllWords, ibis::qKeyword, ibis::qLike, ibis::qAnyString, ibis::qString, and ibis::qRange.

Referenced by ibis::quaere::create().

virtual bool ibis::qExpr::isConstant ( ) const
inlinevirtual

Is this expression a constant? A constant remains the same not matter which row it is applied to.

Reimplemented in ibis::compRange, ibis::math::literal, and ibis::math::number.

Referenced by ibis::countQuery::doEstimate(), ibis::countQuery::doEvaluate(), ibis::query::doEvaluate(), ibis::countQuery::doScan(), ibis::query::doScan(), and simplify().

virtual bool ibis::qExpr::isSimple ( ) const
inlinevirtual

Is the expression simple? A simple expression contains only range conditions connected with logical operators.

Reimplemented in ibis::compRange, and ibis::qExists.

void ibis::qExpr::print ( std::ostream &  out) const
virtual
void ibis::qExpr::printFull ( std::ostream &  out) const
virtual
double ibis::qExpr::reorder ( const weight wt)

After reordering, the lightest weight is one the left side of a group of commutable operators.

References directEval(), left, reorder(), right, and type.

Referenced by reorder().

int ibis::qExpr::separateSimple ( ibis::qExpr *&  simple,
ibis::qExpr *&  tail 
) const

Separate an expression tree into two connected with an AND operator.

The terms that are simply range conditions are placed in simple, and the remaining conditions are left in tail.

It returns 0 if there is a mixture of simple and complex conditions. In this case, both simple and tail would be non-nil. The return value is -1 if all conditions are complex and 1 if all conditions are simple. In these two cases, both simple and tail are nil.

References left, print(), right, and type.

Referenced by ibis::query::removeComplexConditions().

void ibis::qExpr::setLeft ( qExpr expr)
inline

Change the left child.

This object takes the ownership of expr. The user can not delete expr either directly or indirectly through the destruction of another object (other than this one, of course).

References left.

Referenced by ibis::quaere::create(), ibis::math::bediener::dup(), ibis::math::stdFunction1::dup(), ibis::math::stdFunction2::dup(), fastbit_selection_combine(), fastbit_selection_create(), fastbit_selection_create_nd(), fastbit_selection_osr(), ibis::query::setWhereClause(), and simplify().

void ibis::qExpr::setRight ( qExpr expr)
inline

Change the right child.

This object takes the ownership of expr. The user can not delete expr either directly or indirectly through the destruction of another object (other than this one, of course).

References right.

Referenced by ibis::quaere::create(), ibis::math::bediener::dup(), ibis::math::stdFunction2::dup(), fastbit_selection_combine(), ibis::query::setWhereClause(), and simplify().

void ibis::qExpr::simplify ( ibis::qExpr *&  expr)
static

Attempt to simplify the query expressions.

Operations performed include converting compRanges into qRanges, qDiscreteRange into qContinuousRange, perform constant evaluations, combining pairs of inverse functions.

This is necessary because the parser always generates compRange instead of qRange. The goal of simplifying arithmetic expressions is to reduce the number of accesses to the variable values (potentially reducing the number of disk accesses).

Note
Be aware that rearranging the arithmetic expressions may affect the round-off perperties of these expressions, and therefore affect their computed results. Even though the typical differences might be small (after ten significant digits), however, the differences could accumulated and became noticeable. To turn off this optimization, set ibis::math::preserveInputExpressions to true.

References ibis::qDiscreteRange::convert(), ibis::qAnyString::convert(), ibis::math::term::eval(), getLeft(), getRight(), getType(), ibis::qContinuousRange::inRange(), isConstant(), left, ibis::compRange::makeConstantFalse(), ibis::qDiscreteRange::nItems(), ibis::math::preserveInputExpressions, print(), printFull(), ibis::math::term::reduce(), right, setLeft(), setRight(), type, and ibis::qAnyString::valueList().

Referenced by ibis::whereClause::amplify(), ibis::whereClause::parse(), and ibis::whereClause::simplify().

void ibis::qExpr::splitColumnName ( const char *  inm,
std::string &  pn,
std::string &  cn 
)
static

Split the incoming name into data partition name and column name.

It looks for the first period '.' in the incoming name. If a period is found, the characters before the period is returned as pn, and the characters after the period is returned as cn. If no period is found, pn will be a blank string and cn will be a copy of inm.

Note
Both output names will be in lower case only.

Member Data Documentation

TYPE ibis::qExpr::type
protected

The type of node.

It indicates the type of the operator or the leaf node.

Referenced by getType(), reorder(), separateSimple(), simplify(), and swap().


The documentation for this class was generated from the following files:

Make It A Bit Faster
Contact us
Disclaimers
FastBit source code
FastBit mailing list archive