1 /* 2 Copyright (c) 2019-20 MariaDB 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; version 2 of the License. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 16 17 18 #ifndef HA_MCS_PUSH 19 #define HA_MCS_PUSH 20 21 #include "idb_mysql.h" 22 #include "ha_mcs.h" 23 #include "ha_mcs_sysvars.h" 24 #define NEED_CALPONT_EXTERNS 25 #include "ha_mcs_impl.h" 26 #include "ha_mcs_impl_if.h" 27 #include "ha_mcs_opt_rewrites.h" 28 29 void mutate_optimizer_flags(THD *thd_); 30 void restore_optimizer_flags(THD *thd_); 31 32 enum mcs_handler_types_t 33 { 34 SELECT, 35 DERIVED, 36 GROUP_BY, 37 LEGACY 38 }; 39 40 struct mcs_handler_info 41 { mcs_handler_infomcs_handler_info42 mcs_handler_info() : hndl_ptr(NULL), hndl_type(LEGACY) { }; mcs_handler_infomcs_handler_info43 mcs_handler_info(mcs_handler_types_t type) : hndl_ptr(NULL), hndl_type(type) { }; mcs_handler_infomcs_handler_info44 mcs_handler_info(void* ptr, mcs_handler_types_t type) : hndl_ptr(ptr), hndl_type(type) { }; ~mcs_handler_infomcs_handler_info45 ~mcs_handler_info() { }; 46 void* hndl_ptr; 47 mcs_handler_types_t hndl_type; 48 }; 49 50 /*@brief group_by_handler class*/ 51 /*********************************************************** 52 * DESCRIPTION: 53 * Provides server with group_by_handler API methods. 54 * One should read comments in server/sql/group_by_handler.h 55 * Attributes: 56 * select - attribute contains all GROUP BY, HAVING, ORDER items and calls it 57 * an extended SELECT list according to comments in 58 * server/sql/group_handler.cc. 59 * So the temporary table for 60 * select count(*) from b group by a having a > 3 order by a 61 * will have 4 columns not 1. 62 * However server ignores all NULLs used in 63 * GROUP BY, HAVING, ORDER. 64 * select_list_descr - contains Item description returned by Item->print() 65 * that is used in lookup for corresponding columns in 66 * extended SELECT list. 67 * table_list - contains all tables involved. Must be CS tables only. 68 * distinct - looks like a useless thing for now. Couldn't get it set by server. 69 * where - where items. 70 * group_by - group by ORDER items. 71 * order_by - order by ORDER items. 72 * having - having Item. 73 * Methods: 74 * init_scan - get plan and send it to ExeMgr. Get the execution result. 75 * next_row - get a row back from sm. 76 * end_scan - finish and clean the things up. 77 ***********************************************************/ 78 class ha_mcs_group_by_handler: public group_by_handler 79 { 80 public: 81 ha_mcs_group_by_handler(THD* thd_arg, Query* query); 82 ~ha_mcs_group_by_handler(); 83 int init_scan() override; 84 int next_row() override; 85 int end_scan() override; 86 87 List<Item>* select; 88 TABLE_LIST* table_list; 89 bool distinct; 90 Item* where; 91 ORDER* group_by; 92 ORDER* order_by; 93 Item* having; 94 }; 95 96 /*@brief derived_handler class*/ 97 /*********************************************************** 98 * DESCRIPTION: 99 * derived_handler API methods. Could be used by the server 100 * tp process sub-queries. 101 * More details in server/sql/dervied_handler.h 102 * COLUMNSTORE_SHARE* hton share 103 * tbl in the constructor is the list of the tables involved. 104 * Methods: 105 * init_scan - get plan and send it to ExeMgr. Get the execution result. 106 * next_row - get a row back from sm. 107 * end_scan - finish and clean the things up. 108 ***********************************************************/ 109 class ha_columnstore_derived_handler: public derived_handler 110 { 111 private: 112 COLUMNSTORE_SHARE *share; 113 114 public: 115 ha_columnstore_derived_handler(THD* thd_arg, TABLE_LIST *tbl); 116 ~ha_columnstore_derived_handler(); 117 int init_scan() override; 118 int next_row() override; 119 int end_scan() override; 120 void print_error(int, unsigned long); 121 }; 122 123 /*@brief select_handler class*/ 124 /*********************************************************** 125 * DESCRIPTION: 126 * select_handler API methods. Could be used by the server 127 * tp pushdown the whole query described by SELECT_LEX. 128 * More details in server/sql/select_handler.h 129 * COLUMNSTORE_SHARE* hton share 130 * sel in the constructor is the semantic tree for the query. 131 * Methods: 132 * init_scan - get plan and send it to ExeMgr. Get the execution result. 133 * next_row - get a row back from sm. 134 * end_scan - finish and clean the things up. 135 ***********************************************************/ 136 class ha_columnstore_select_handler: public select_handler 137 { 138 private: 139 COLUMNSTORE_SHARE *share; 140 141 public: 142 bool rewrite_error; 143 std::string err_msg; 144 ha_columnstore_select_handler(THD* thd_arg, SELECT_LEX* sel); 145 ~ha_columnstore_select_handler(); 146 int init_scan() override; 147 int next_row() override; 148 int end_scan() override; 149 }; 150 151 #endif 152