00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*- 00002 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab: 00003 * 00004 * Copyright (C) 2009 Sun Microsystems, Inc. 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; version 2 of the License. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00020 #pragma once 00021 00022 #include <drizzled/common_fwd.h> 00023 00024 namespace drizzled { 00025 00026 00027 struct ReadRecord { /* Parameter to read_record */ 00028 Table *table; /* Head-form */ 00029 Cursor *cursor; 00030 Table **forms; /* head and ref forms */ 00031 int (*read_record)(ReadRecord *); 00032 Session *session; 00033 optimizer::SqlSelect *select; 00034 uint32_t cache_records; 00035 uint32_t ref_length; 00036 uint32_t struct_length; 00037 uint32_t reclength; 00038 uint32_t rec_cache_size; 00039 uint32_t error_offset; 00040 uint32_t index; 00041 unsigned char *ref_pos; /* pointer to form->refpos */ 00042 unsigned char *record; 00043 unsigned char *rec_buf; /* to read field values after filesort */ 00044 private: 00045 unsigned char *cache; 00046 public: 00047 unsigned char *getCache() 00048 { 00049 return cache; 00050 } 00051 unsigned char *cache_pos; 00052 unsigned char *cache_end; 00053 unsigned char *read_positions; 00054 internal::io_cache_st *io_cache; 00055 bool print_error; 00056 bool ignore_not_found_rows; 00057 JoinTable *do_insideout_scan; 00058 ReadRecord() : 00059 table(NULL), 00060 cursor(NULL), 00061 forms(0), 00062 read_record(0), 00063 session(0), 00064 select(0), 00065 cache_records(0), 00066 ref_length(0), 00067 struct_length(0), 00068 reclength(0), 00069 rec_cache_size(0), 00070 error_offset(0), 00071 index(0), 00072 ref_pos(0), 00073 record(0), 00074 rec_buf(0), 00075 cache(0), 00076 cache_pos(0), 00077 cache_end(0), 00078 read_positions(0), 00079 io_cache(0), 00080 print_error(0), 00081 ignore_not_found_rows(0), 00082 do_insideout_scan(0) 00083 { 00084 } 00085 00086 void init() 00087 { 00088 table= NULL; 00089 cursor= NULL; 00090 forms= 0; 00091 read_record= 0; 00092 session= 0; 00093 select= 0; 00094 cache_records= 0; 00095 ref_length= 0; 00096 struct_length= 0; 00097 reclength= 0; 00098 rec_cache_size= 0; 00099 error_offset= 0; 00100 index= 0; 00101 ref_pos= 0; 00102 record= 0; 00103 rec_buf= 0; 00104 cache= 0; 00105 cache_pos= 0; 00106 cache_end= 0; 00107 read_positions= 0; 00108 io_cache= 0; 00109 print_error= 0; 00110 ignore_not_found_rows= 0; 00111 do_insideout_scan= 0; 00112 } 00113 00114 virtual ~ReadRecord() 00115 { } 00116 00117 /* 00118 init_read_record is used to scan by using a number of different methods. 00119 Which method to use is set-up in this call so that later calls to 00120 the info->read_record will call the appropriate method using a function 00121 pointer. 00122 00123 There are five methods that relate completely to the sort function 00124 filesort. The result of a filesort is retrieved using read_record 00125 calls. The other two methods are used for normal table access. 00126 00127 The filesort will produce references to the records sorted, these 00128 references can be stored in memory or in a temporary cursor. 00129 00130 The temporary cursor is normally used when the references doesn't fit into 00131 a properly sized memory buffer. For most small queries the references 00132 are stored in the memory buffer. 00133 00134 The temporary cursor is also used when performing an update where a key is 00135 modified. 00136 00137 Methods used when ref's are in memory (using rr_from_pointers): 00138 rr_unpack_from_buffer: 00139 ---------------------- 00140 This method is used when table->sort.addon_field is allocated. 00141 This is allocated for most SELECT queries not involving any BLOB's. 00142 In this case the records are fetched from a memory buffer. 00143 rr_from_pointers: 00144 ----------------- 00145 Used when the above is not true, UPDATE, DELETE and so forth and 00146 SELECT's involving BLOB's. It is also used when the addon_field 00147 buffer is not allocated due to that its size was bigger than the 00148 session variable max_length_for_sort_data. 00149 In this case the record data is fetched from the handler using the 00150 saved reference using the rnd_pos handler call. 00151 00152 Methods used when ref's are in a temporary cursor (using rr_from_tempfile) 00153 rr_unpack_from_tempfile: 00154 ------------------------ 00155 Same as rr_unpack_from_buffer except that references are fetched from 00156 temporary cursor. Should obviously not really happen other than in 00157 strange configurations. 00158 00159 rr_from_tempfile: 00160 ----------------- 00161 Same as rr_from_pointers except that references are fetched from 00162 temporary cursor instead of from 00163 rr_from_cache: 00164 -------------- 00165 This is a special variant of rr_from_tempfile that can be used for 00166 handlers that is not using the HA_FAST_KEY_READ table flag. Instead 00167 of reading the references one by one from the temporary cursor it reads 00168 a set of them, sorts them and reads all of them into a buffer which 00169 is then used for a number of subsequent calls to rr_from_cache. 00170 It is only used for SELECT queries and a number of other conditions 00171 on table size. 00172 00173 All other accesses use either index access methods (rr_quick) or a full 00174 table scan (rr_sequential). 00175 rr_quick: 00176 --------- 00177 rr_quick uses one of the QUICK_SELECT classes in optimizer/range.cc to 00178 perform an index scan. There are loads of functionality hidden 00179 in these quick classes. It handles all index scans of various kinds. 00180 rr_sequential: 00181 -------------- 00182 This is the most basic access method of a table using rnd_init, 00183 rnd_next and rnd_end. No indexes are used. 00184 */ 00185 int init_read_record(Session *session, 00186 Table *reg_form, 00187 optimizer::SqlSelect *select, 00188 int use_record_cache, 00189 bool print_errors) __attribute__ ((warn_unused_result)); 00190 00191 void end_read_record(); 00192 00193 00209 int init_read_record_idx(Session *session, 00210 Table *table, 00211 bool print_error, 00212 uint32_t idx) __attribute__ ((warn_unused_result)); 00213 00214 void init_reard_record_sequential(); 00215 00216 bool init_rr_cache(); 00217 }; 00218 00219 } /* namespace drizzled */ 00220