Column-oriented GPU-accelerated Database Management System
CoGaDB
/home/sebastian/gpudbms/trunk/cogadb/include/query_processing/sort_operator.hpp
Go to the documentation of this file.
00001 #pragma once
00002 
00003 #include <query_processing/definitions.hpp>
00004 #include <core/runtime_configuration.hpp>
00005 
00006 namespace CoGaDB {
00007     namespace query_processing {
00008         namespace physical_operator {
00009 
00010             class CPU_Sort_Operator : public hype::queryprocessing::UnaryOperator<TablePtr, TablePtr> {
00011             public:
00012                 typedef hype::queryprocessing::OperatorMapper_Helper_Template<TablePtr>::TypedOperatorPtr TypedOperatorPtr;
00013 
00014                 CPU_Sort_Operator(const hype::SchedulingDecision& sched_dec,
00015                         TypedOperatorPtr child,
00016                         const std::list<std::string>& column_names,
00017                         SortOrder order = ASCENDING,
00018                         MaterializationStatus mat_stat = MATERIALIZE)
00019                 : UnaryOperator<TablePtr, TablePtr>(sched_dec, child),
00020                 column_names_(column_names),
00021                 order_(order),
00022                 mat_stat_(mat_stat) {
00023                 }
00024 
00025                 virtual bool execute() {
00026                     //std::cout << "Execute Sort CPU" << std::endl;
00027                     //const TablePtr sort(TablePtr table, const std::string& column_name, SortOrder order=ASCENDING, MaterializationStatus mat_stat=MATERIALIZE, ComputeDevice comp_dev=CPU);
00028                     this->result_ = BaseTable::sort(this->getInputData(), column_names_, order_, mat_stat_, CPU);
00029                     //                                          std::cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
00030                     //                                          std::cout << "INPUT:" << std::endl;
00031                     //                                          this->getInputData()->print();
00032                     //                                          std::cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
00033                     //                                          std::cout << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl;
00034                     //                                          std::cout << "OUTPUT:" << std::endl;
00035                     //                                          this->result_->print();
00036                     //                                          std::cout << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl;
00037                     if (this->result_) {
00038                         setResultSize(((TablePtr) this->result_)->getNumberofRows());
00039                         return true;
00040                     } else
00041                         return false;
00042                 }
00043 
00044                 virtual ~CPU_Sort_Operator() {
00045                 }
00046             private:
00047                 std::list<std::string> column_names_;
00048                 SortOrder order_;
00049                 MaterializationStatus mat_stat_;
00050             };
00051 
00052             class GPU_Sort_Operator : public hype::queryprocessing::UnaryOperator<TablePtr, TablePtr> {
00053             public:
00054                 typedef hype::queryprocessing::OperatorMapper_Helper_Template<TablePtr>::TypedOperatorPtr TypedOperatorPtr;
00055 
00056                 GPU_Sort_Operator(const hype::SchedulingDecision& sched_dec,
00057                         TypedOperatorPtr child,
00058                         const std::list<std::string>& column_names,
00059                         SortOrder order = ASCENDING,
00060                         MaterializationStatus mat_stat = MATERIALIZE) : UnaryOperator<TablePtr, TablePtr>(sched_dec, child),
00061                 column_names_(column_names),
00062                 order_(order),
00063                 mat_stat_(mat_stat) {
00064                 }
00065 
00066                 virtual bool execute() {
00067                     //std::cout << "Execute Sort GPU" << std::endl;
00068                     //const TablePtr sort(TablePtr table, const std::string& column_name, SortOrder order=ASCENDING, MaterializationStatus mat_stat=MATERIALIZE, ComputeDevice comp_dev=CPU);
00069 
00070 
00071                     //                                          std::cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
00072                     //std::cout << "INPUT:" << std::endl;
00073                     //this->getInputData()->print();
00074 
00075                     this->result_ = BaseTable::sort(this->getInputData(), column_names_, order_, mat_stat_, GPU);
00076                     //                                          std::cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
00077                     //                                          std::cout << "INPUT:" << std::endl;
00078                     //                                          this->getInputData()->print();
00079                     //                                          std::cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
00080                     //                                          std::cout << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl;
00081                     //                                          std::cout << "OUTPUT:" << std::endl;
00082                     //                                          this->result_->print();
00083                     //                                          std::cout << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl;
00084                     //this->result_->print();
00085                     if (this->result_) {
00086                         setResultSize(((TablePtr) this->result_)->getNumberofRows());
00087                         return true;
00088                     } else
00089                         return false;
00090                 }
00091 
00092                 virtual ~GPU_Sort_Operator() {
00093                 }
00094             private:
00095                 std::list<std::string> column_names_;
00096                 SortOrder order_;
00097                 MaterializationStatus mat_stat_;
00098             };
00099 
00100             Physical_Operator_Map_Ptr map_init_function_sort_operator();
00101                         TypedOperatorPtr create_CPU_SORT_Operator(TypedLogicalNode& logical_node, const hype::SchedulingDecision&, TypedOperatorPtr left_child, TypedOperatorPtr right_child);
00102                         TypedOperatorPtr create_GPU_SORT_Operator(TypedLogicalNode& logical_node, const hype::SchedulingDecision&, TypedOperatorPtr left_child, TypedOperatorPtr right_child);
00103 
00104         }//end namespace physical_operator
00105 
00106         //extern Map_Init_Function init_function_sort_operator;
00107 
00108         //Map_Init_Function init_function_sort_operator=physical_operator::map_init_function_sort_operator; //boost::bind();
00109 
00110         namespace logical_operator {
00111 
00112                         class Logical_Sort : public hype::queryprocessing::TypedNode_Impl<TablePtr,physical_operator::map_init_function_sort_operator> //init_function_sort_operator>
00113             {
00114             public:
00115 
00116                 Logical_Sort(const std::list<std::string>& column_names,
00117                         SortOrder order = ASCENDING,
00118                         MaterializationStatus mat_stat = MATERIALIZE,
00119                         hype::DeviceConstraint dev_constr = CoGaDB::RuntimeConfiguration::instance().getGlobalDeviceConstraint())
00120                 : TypedNode_Impl<TablePtr, physical_operator::map_init_function_sort_operator>(false, dev_constr),
00121                 column_names_(column_names),
00122                 order_(order),
00123                 mat_stat_(mat_stat) {
00124                 }
00125 
00126                 virtual unsigned int getOutputResultSize() const {
00127                     return 10;
00128                 }
00129 
00130                 virtual double getCalculatedSelectivity() const {
00131                     return 0.1;
00132                 }
00133 
00134                 virtual std::string getOperationName() const {
00135                     return "SORT";
00136                 }
00137                 std::string toString(bool verbose) const{
00138                     std::string result="SORT";
00139                     if(verbose){
00140                         result+=" BY (";
00141                         std::list<std::string>::const_iterator cit;
00142                         for(cit=column_names_.begin();cit!=column_names_.end();++cit){
00143                             result+=*cit;
00144                             if(cit!=--column_names_.end())
00145                                 result+=",";
00146                         }
00147                         result+=")";
00148                     }
00149                     return result;
00150 
00151                 }
00152                 const std::list<std::string>& getColumnNames() {
00153                     return column_names_;
00154                 }
00155 
00156                 SortOrder getSortOrder() {
00157                     return order_;
00158                 }
00159 
00160                 MaterializationStatus getMaterializationStatus() {
00161                     return mat_stat_;
00162                 }
00163                 std::list<std::string> column_names_;
00164                 SortOrder order_;
00165                 MaterializationStatus mat_stat_;
00166             };
00167 
00168         }//end namespace logical_operator
00169 
00170     }//end namespace query_processing
00171 
00172 }; //end namespace CogaDB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines