1 #ifndef SQL_RECORDS_H 2 #define SQL_RECORDS_H 3 /* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; version 2 of the License. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software 16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ 17 18 #ifdef USE_PRAGMA_INTERFACE 19 #pragma interface /* gcc class implementation */ 20 #endif 21 22 #include "table.h" 23 24 struct st_join_table; 25 class handler; 26 class THD; 27 class SQL_SELECT; 28 class Copy_field; 29 class SORT_INFO; 30 31 struct READ_RECORD; 32 33 void end_read_record(READ_RECORD *info); 34 void free_cache(READ_RECORD *info); 35 36 /** 37 A context for reading through a single table using a chosen access method: 38 index read, scan, etc, use of cache, etc. 39 40 Use by: 41 READ_RECORD read_record; 42 init_read_record(&read_record, ...); 43 while (read_record.read_record()) 44 { 45 ... 46 } 47 end_read_record(); 48 */ 49 50 struct READ_RECORD 51 { 52 typedef int (*Read_func)(READ_RECORD*); 53 typedef void (*Unlock_row_func)(st_join_table *); 54 typedef int (*Setup_func)(struct st_join_table*); 55 56 TABLE *table; /* Head-form */ 57 Unlock_row_func unlock_row; 58 Read_func read_record_func; 59 THD *thd; 60 SQL_SELECT *select; 61 uint ref_length, reclength, rec_cache_size, error_offset; 62 63 /** 64 Counting records when reading result from filesort(). 65 Used when filesort leaves the result in the filesort buffer. 66 */ 67 ha_rows unpack_counter; 68 69 uchar *ref_pos; /* pointer to form->refpos */ 70 uchar *rec_buf; /* to read field values after filesort */ 71 uchar *cache,*cache_pos,*cache_end,*read_positions; 72 73 /* 74 Structure storing information about sorting 75 */ 76 SORT_INFO *sort_info; 77 struct st_io_cache *io_cache; 78 bool print_error; 79 read_recordREAD_RECORD80 int read_record() { return read_record_func(this); } recordREAD_RECORD81 uchar *record() const { return table->record[0]; } 82 83 /* 84 SJ-Materialization runtime may need to read fields from the materialized 85 table and unpack them into original table fields: 86 */ 87 Copy_field *copy_field; 88 Copy_field *copy_field_end; 89 public: READ_RECORDREAD_RECORD90 READ_RECORD() : table(NULL), cache(NULL) {} ~READ_RECORDREAD_RECORD91 ~READ_RECORD() { end_read_record(this); } 92 }; 93 94 bool init_read_record(READ_RECORD *info, THD *thd, TABLE *reg_form, 95 SQL_SELECT *select, SORT_INFO *sort, 96 int use_record_cache, 97 bool print_errors, bool disable_rr_cache); 98 bool init_read_record_idx(READ_RECORD *info, THD *thd, TABLE *table, 99 bool print_error, uint idx, bool reverse); 100 101 void rr_unlock_row(st_join_table *tab); 102 103 #endif /* SQL_RECORDS_H */ 104