The top level query expression object. More...
#include <qExpr.h>
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< TTN > | termTableList |
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 qExpr * | dup () const |
!< Reorder the expressions tree. More... | |
void | extractDeprecatedJoins (std::vector< const deprecatedJoin * > &) const |
Extract conjunctive terms of the deprecated joins. | |
qRange * | findRange (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 qExpr * | getLeft () const |
Return a const pointer to the left child. | |
qExpr *& | getRight () |
Return a pointer to the right child. More... | |
const qExpr * | getRight () 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. | |
qExpr & | operator= (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 | |
qExpr * | left |
The left child. | |
qExpr * | right |
The right child. | |
TYPE | type |
The type of node. More... | |
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.
enum ibis::qExpr::TYPE |
Definition of node types.
Logical operators are listed in the front and leaf node types are listed at the end.
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.
|
inlinevirtual |
|
protected |
|
inlinevirtual |
!< Reorder the expressions tree.
Duplicate this query expression. Return the pointer to the new object.
Reimplemented in ibis::qAnyAny, ibis::deprecatedJoin, ibis::compRange, ibis::math::stringFunction1, ibis::math::customFunction1, ibis::math::stdFunction2, ibis::math::stdFunction1, ibis::math::bediener, ibis::math::literal, ibis::math::number, ibis::math::variable, ibis::math::term, ibis::qAllWords, ibis::qKeyword, ibis::qLike, ibis::qAnyString, ibis::qExists, ibis::qString, ibis::qUIntHod, ibis::qIntHod, ibis::qDiscreteRange, ibis::qContinuousRange, and ibis::selectClause::variable.
Referenced by ibis::whereClause::addExpr(), ibis::whereClause::setExpr(), and ibis::whereClause::whereClause().
|
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.
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().
|
inline |
Return a pointer to the left child.
The pointer can be modified. The object assigned to be the new left child is owned by this object.
References left.
Referenced by ibis::whereClause::amplify(), ibis::quaere::create(), ibis::query::doContract(), ibis::countQuery::doEstimate(), ibis::countQuery::doEvaluate(), ibis::query::doExpand(), ibis::countQuery::doScan(), ibis::part::doScan(), ibis::query::doScan(), ibis::math::bediener::dup(), ibis::math::stdFunction1::dup(), ibis::math::stdFunction2::dup(), ibis::selectClause::hasAggregation(), ibis::compRange::isConstant(), ibis::query::weight::operator()(), ibis::math::barrel::recordVariable(), ibis::math::bediener::reduce(), ibis::math::stdFunction1::reduce(), simplify(), ibis::whereClause::verifyExpr(), and ibis::selectClause::verifyTerm().
|
inline |
Return a pointer to the right child.
The pointer can be modified. The object assigned to be the new right child of this expression is owned by this object after the assignment.
References right.
Referenced by ibis::whereClause::amplify(), ibis::quaere::create(), ibis::query::doContract(), ibis::countQuery::doEstimate(), ibis::countQuery::doEvaluate(), ibis::query::doExpand(), ibis::countQuery::doScan(), ibis::part::doScan(), ibis::query::doScan(), ibis::math::bediener::dup(), ibis::math::stdFunction2::dup(), ibis::selectClause::hasAggregation(), ibis::compRange::isConstant(), ibis::query::weight::operator()(), ibis::math::barrel::recordVariable(), ibis::math::bediener::reduce(), simplify(), ibis::whereClause::verifyExpr(), and ibis::selectClause::verifyTerm().
|
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().
|
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().
|
inlinevirtual |
Is the expression simple? A simple expression contains only range conditions connected with logical operators.
Reimplemented in ibis::compRange, and ibis::qExists.
|
virtual |
Print out the node in the string form.
The short-form of the print function.
It only prints information about the current node of the query expression tree.
Reimplemented in ibis::qAnyAny, ibis::deprecatedJoin, ibis::compRange, ibis::math::stringFunction1, ibis::math::customFunction1, ibis::math::stdFunction2, ibis::math::stdFunction1, ibis::math::bediener, ibis::math::literal, ibis::math::number, ibis::math::variable, ibis::math::term, ibis::qAllWords, ibis::qKeyword, ibis::qLike, ibis::qAnyString, ibis::qExists, ibis::qString, ibis::qUIntHod, ibis::qIntHod, ibis::qDiscreteRange, ibis::qContinuousRange, and ibis::selectClause::variable.
Referenced by ibis::qDiscreteRange::printFull(), ibis::qString::printFull(), ibis::qAnyString::printFull(), ibis::qLike::printFull(), ibis::qKeyword::printFull(), ibis::qAllWords::printFull(), ibis::query::removeComplexConditions(), separateSimple(), and simplify().
|
virtual |
Print out the full expression.
The long form of the print function.
It recursively prints out the whole query expression tree, which can be quite long.
Reimplemented in ibis::qAnyAny, ibis::deprecatedJoin, ibis::compRange, ibis::math::stringFunction1, ibis::math::customFunction1, ibis::math::stdFunction2, ibis::math::stdFunction1, ibis::math::bediener, ibis::math::literal, ibis::math::number, ibis::math::variable, ibis::math::term, ibis::qAllWords, ibis::qKeyword, ibis::qLike, ibis::qAnyString, ibis::qExists, ibis::qString, ibis::qUIntHod, ibis::qIntHod, ibis::qDiscreteRange, and ibis::qContinuousRange.
Referenced by ibis::query::setWhereClause(), and simplify().
double ibis::qExpr::reorder | ( | const weight & | wt | ) |
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().
|
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().
|
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().
|
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).
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().
|
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.
|
protected |
The type of node.
It indicates the type of the operator or the leaf node.
Referenced by getType(), reorder(), separateSimple(), simplify(), and swap().