Column-oriented GPU-accelerated Database Management System
CoGaDB
/home/sebastian/gpudbms/trunk/cogadb/include/query_processing/selection_operator.hpp
Go to the documentation of this file.
00001 #pragma once
00002 
00003 #include <query_processing/definitions.hpp>
00004 #include <util/iostream.hpp>
00005 #include <util/getname.hpp>
00006 #include <sstream> 
00007 
00008 #include <core/selection_expression.hpp>
00009 
00010 namespace CoGaDB {
00011     namespace query_processing {
00012         namespace physical_operator {
00013 
00014             class CPU_Selection_Operator : public hype::queryprocessing::UnaryOperator<TablePtr, TablePtr> {
00015             public:
00016                 typedef hype::queryprocessing::OperatorMapper_Helper_Template<TablePtr>::TypedOperatorPtr TypedOperatorPtr;
00017 
00018                 CPU_Selection_Operator(const hype::SchedulingDecision& sched_dec,
00019                         TypedOperatorPtr child,
00020                         Predicate pred,
00021                         MaterializationStatus mat_stat = MATERIALIZE) : UnaryOperator<TablePtr, TablePtr>(sched_dec, child),
00022                         pred_(pred),
00023                 mat_stat_(mat_stat) {
00024                 }
00025 
00026                 virtual bool execute() {
00027                     //std::cout << "Execute Selection CPU" << std::endl;
00028                     //const TablePtr sort(TablePtr table, const std::string& column_name, SortOrder order=ASCENDING, MaterializationStatus mat_stat=MATERIALIZE, ComputeDevice comp_dev=CPU);
00029                     //this->result_=BaseTable::sort(this->getInputData(), column_name_,order_, mat_stat_,CPU);
00030                     //this->result_ = BaseTable::selection(this->getInputData(), column_name_, value_for_comparison_, comp_, mat_stat_, SERIAL);
00031                     assert(pred_.getPredicateType()==ValueConstantPredicate);
00032                     this->result_ = BaseTable::selection(this->getInputData(), pred_.getColumn1Name(), pred_.getConstant(),pred_.getValueComparator(), mat_stat_, SERIAL);
00033                     
00034                     if (this->result_) {
00035                         setResultSize(((TablePtr) this->result_)->getNumberofRows());
00036                         return true;
00037                     } else
00038                         return false;
00039                 }
00040 
00041                 virtual ~CPU_Selection_Operator() {
00042                 }
00043             private:
00044                 Predicate pred_;
00045                 MaterializationStatus mat_stat_;
00046             };
00047 
00048             class CPU_ParallelSelection_Operator : public hype::queryprocessing::UnaryOperator<TablePtr, TablePtr> {
00049             public:
00050                 typedef hype::queryprocessing::OperatorMapper_Helper_Template<TablePtr>::TypedOperatorPtr TypedOperatorPtr;
00051 
00052                 CPU_ParallelSelection_Operator(const hype::SchedulingDecision& sched_dec,
00053                         TypedOperatorPtr child,
00054                         Predicate pred,
00055                         MaterializationStatus mat_stat = MATERIALIZE) : UnaryOperator<TablePtr, TablePtr>(sched_dec, child),
00056                         pred_(pred),
00057                 mat_stat_(mat_stat) {
00058                 }
00059 
00060                 virtual bool execute() {
00061                     assert(pred_.getPredicateType()==ValueConstantPredicate);
00062                     this->result_ = BaseTable::selection(this->getInputData(), pred_.getColumn1Name(), pred_.getConstant(),pred_.getValueComparator(), mat_stat_, PARALLEL);
00063 
00064                     if (this->result_) {
00065                         setResultSize(((TablePtr) this->result_)->getNumberofRows());
00066                         return true;
00067                     } else
00068                         return false;
00069                 }
00070 
00071                 virtual ~CPU_ParallelSelection_Operator() {
00072                 }
00073             private:
00074                 Predicate pred_;
00075                 MaterializationStatus mat_stat_;
00076             };
00077 
00078             class GPU_Selection_Operator : public hype::queryprocessing::UnaryOperator<TablePtr, TablePtr> {
00079             public:
00080                 typedef hype::queryprocessing::OperatorMapper_Helper_Template<TablePtr>::TypedOperatorPtr TypedOperatorPtr;
00081 
00082                 GPU_Selection_Operator(const hype::SchedulingDecision& sched_dec,
00083                         TypedOperatorPtr child,
00084                         Predicate pred,
00085                         MaterializationStatus mat_stat = MATERIALIZE) : UnaryOperator<TablePtr, TablePtr>(sched_dec, child),
00086                         pred_(pred),
00087                 mat_stat_(mat_stat) {
00088                 }
00089 
00090                 virtual bool execute() {
00091                     //std::cout << "Execute Selection GPU" << std::endl;
00092                     //const TablePtr sort(TablePtr table, const std::string& column_name, SortOrder order=ASCENDING, MaterializationStatus mat_stat=MATERIALIZE, ComputeDevice comp_dev=CPU);
00093                     //this->result_ = BaseTable::selection(this->getInputData(), column_name_, value_for_comparison_, comp_, mat_stat_, PARALLEL, GPU);
00094                     assert(pred_.getPredicateType()==ValueConstantPredicate);
00095                     this->result_ = BaseTable::selection(this->getInputData(), pred_.getColumn1Name(), pred_.getConstant(),pred_.getValueComparator(), mat_stat_, PARALLEL, GPU);
00096                     
00097                     
00098                     if (this->result_){
00099                         setResultSize(((TablePtr) this->result_)->getNumberofRows());
00100                         return true;
00101                      } else
00102                         return false;
00103                 }
00104 
00105                 virtual ~GPU_Selection_Operator() {
00106                 }
00107             private:
00108                 Predicate pred_;
00109                 MaterializationStatus mat_stat_;
00110             };
00111 
00112             Physical_Operator_Map_Ptr map_init_function_selection_operator();
00113             TypedOperatorPtr create_CPU_Selection_Operator(TypedLogicalNode& logical_node, const hype::SchedulingDecision&, TypedOperatorPtr left_child, TypedOperatorPtr right_child);
00114             TypedOperatorPtr create_CPU_ParallelSelection_Operator(TypedLogicalNode& logical_node, const hype::SchedulingDecision&, TypedOperatorPtr left_child, TypedOperatorPtr right_child);
00115             TypedOperatorPtr create_GPU_Selection_Operator(TypedLogicalNode& logical_node, const hype::SchedulingDecision&, TypedOperatorPtr left_child, TypedOperatorPtr right_child);
00116 
00117         }//end namespace physical_operator
00118 
00119         //extern Map_Init_Function init_function_Selection_operator;
00120 
00121         //Map_Init_Function init_function_Selection_operator=physical_operator::map_init_function_Selection_operator; //boost::bind();
00122 
00123         namespace logical_operator {
00124 
00125                         class Logical_Selection : public hype::queryprocessing::TypedNode_Impl<TablePtr,physical_operator::map_init_function_selection_operator> //init_function_Selection_operator>
00126             {
00127             public:
00128 
00129                 Logical_Selection(std::string column_name,
00130                         const boost::any& value_for_comparison,
00131                         const ValueComparator& comp,
00132                         MaterializationStatus mat_stat = MATERIALIZE,
00133                         hype::DeviceConstraint dev_constr = hype::DeviceConstraint()
00134                         ) : TypedNode_Impl<TablePtr, physical_operator::map_init_function_selection_operator>(false, dev_constr),
00135                         pred_(Predicate(column_name,value_for_comparison,ValueConstantPredicate,comp)), mat_stat_(mat_stat) {
00136                 }
00137                         
00138                 Logical_Selection(Predicate pred,
00139                         MaterializationStatus mat_stat = MATERIALIZE,
00140                         hype::DeviceConstraint dev_constr = hype::DeviceConstraint()
00141                         ) : TypedNode_Impl<TablePtr, physical_operator::map_init_function_selection_operator>(false, dev_constr),
00142                         pred_(pred), mat_stat_(mat_stat) {
00143                 }
00144 
00145                 virtual unsigned int getOutputResultSize() const {
00146                     return 10;
00147                 }
00148 
00149                 virtual double getCalculatedSelectivity() const {
00150                     return 0.1;
00151                 }
00152 
00153                 virtual std::string getOperationName() const {
00154                     return "SELECTION";
00155                 }
00156                 std::string toString(bool verbose) const{
00157                     std::string result="SELECTION";
00158                     if(verbose){
00159                         result+=" ";
00160                         result+=pred_.toString();
00161                     }
00162                     return result;
00163 
00164                 }
00165                 const Predicate& getPredicate(){
00166                    return pred_;
00167                 }
00168                 
00169                 const MaterializationStatus getMaterializationStatus() const{
00170                     return mat_stat_;
00171                 }
00172             private:
00173                 Predicate pred_;
00174                 MaterializationStatus mat_stat_;
00175             };
00176 
00177         }//end namespace logical_operator
00178 
00179     }//end namespace query_processing
00180 
00181 }; //end namespace CogaDB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines