Drizzled Public API Documentation

records.h

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 namespace drizzled
00023 {
00024 
00025 struct ReadRecord {     /* Parameter to read_record */
00026   Table *table;     /* Head-form */
00027   Cursor *cursor;
00028   Table **forms;      /* head and ref forms */
00029   int (*read_record)(ReadRecord *);
00030   Session *session;
00031   optimizer::SqlSelect *select;
00032   uint32_t cache_records;
00033   uint32_t ref_length;
00034   uint32_t struct_length;
00035   uint32_t reclength;
00036   uint32_t rec_cache_size;
00037   uint32_t error_offset;
00038   uint32_t index;
00039   unsigned char *ref_pos;       /* pointer to form->refpos */
00040   unsigned char *record;
00041   unsigned char *rec_buf;                /* to read field values  after filesort */
00042 private:
00043   unsigned char *cache;
00044 public:
00045   unsigned char *getCache()
00046   {
00047     return cache;
00048   }
00049   unsigned char *cache_pos;
00050   unsigned char *cache_end;
00051   unsigned char *read_positions;
00052   internal::IO_CACHE *io_cache;
00053   bool print_error;
00054   bool ignore_not_found_rows;
00055   JoinTable *do_insideout_scan;
00056   ReadRecord() :
00057     table(NULL),
00058     cursor(NULL),
00059     forms(0),
00060     read_record(0),
00061     session(0),
00062     select(0),
00063     cache_records(0),
00064     ref_length(0),
00065     struct_length(0),
00066     reclength(0),
00067     rec_cache_size(0),
00068     error_offset(0),
00069     index(0),
00070     ref_pos(0),
00071     record(0),
00072     rec_buf(0),
00073     cache(0),
00074     cache_pos(0),
00075     cache_end(0),
00076     read_positions(0),
00077     io_cache(0),
00078     print_error(0),
00079     ignore_not_found_rows(0),
00080     do_insideout_scan(0)
00081   {
00082   }
00083 
00084   void init()
00085   {
00086     table= NULL;
00087     cursor= NULL;
00088     forms= 0;
00089     read_record= 0;
00090     session= 0;
00091     select= 0;
00092     cache_records= 0;
00093     ref_length= 0;
00094     struct_length= 0;
00095     reclength= 0;
00096     rec_cache_size= 0;
00097     error_offset= 0;
00098     index= 0;
00099     ref_pos= 0;
00100     record= 0;
00101     rec_buf= 0;
00102     cache= 0;
00103     cache_pos= 0;
00104     cache_end= 0;
00105     read_positions= 0;
00106     io_cache= 0;
00107     print_error= 0;
00108     ignore_not_found_rows= 0;
00109     do_insideout_scan= 0;
00110   }
00111 
00112   virtual ~ReadRecord()
00113   { }
00114 
00115 /*
00116   init_read_record is used to scan by using a number of different methods.
00117   Which method to use is set-up in this call so that later calls to
00118   the info->read_record will call the appropriate method using a function
00119   pointer.
00120 
00121   There are five methods that relate completely to the sort function
00122   filesort. The result of a filesort is retrieved using read_record
00123   calls. The other two methods are used for normal table access.
00124 
00125   The filesort will produce references to the records sorted, these
00126   references can be stored in memory or in a temporary cursor.
00127 
00128   The temporary cursor is normally used when the references doesn't fit into
00129   a properly sized memory buffer. For most small queries the references
00130   are stored in the memory buffer.
00131 
00132   The temporary cursor is also used when performing an update where a key is
00133   modified.
00134 
00135   Methods used when ref's are in memory (using rr_from_pointers):
00136     rr_unpack_from_buffer:
00137     ----------------------
00138       This method is used when table->sort.addon_field is allocated.
00139       This is allocated for most SELECT queries not involving any BLOB's.
00140       In this case the records are fetched from a memory buffer.
00141     rr_from_pointers:
00142     -----------------
00143       Used when the above is not true, UPDATE, DELETE and so forth and
00144       SELECT's involving BLOB's. It is also used when the addon_field
00145       buffer is not allocated due to that its size was bigger than the
00146       session variable max_length_for_sort_data.
00147       In this case the record data is fetched from the handler using the
00148       saved reference using the rnd_pos handler call.
00149 
00150   Methods used when ref's are in a temporary cursor (using rr_from_tempfile)
00151     rr_unpack_from_tempfile:
00152     ------------------------
00153       Same as rr_unpack_from_buffer except that references are fetched from
00154       temporary cursor. Should obviously not really happen other than in
00155       strange configurations.
00156 
00157     rr_from_tempfile:
00158     -----------------
00159       Same as rr_from_pointers except that references are fetched from
00160       temporary cursor instead of from
00161     rr_from_cache:
00162     --------------
00163       This is a special variant of rr_from_tempfile that can be used for
00164       handlers that is not using the HA_FAST_KEY_READ table flag. Instead
00165       of reading the references one by one from the temporary cursor it reads
00166       a set of them, sorts them and reads all of them into a buffer which
00167       is then used for a number of subsequent calls to rr_from_cache.
00168       It is only used for SELECT queries and a number of other conditions
00169       on table size.
00170 
00171   All other accesses use either index access methods (rr_quick) or a full
00172   table scan (rr_sequential).
00173   rr_quick:
00174   ---------
00175     rr_quick uses one of the QUICK_SELECT classes in optimizer/range.cc to
00176     perform an index scan. There are loads of functionality hidden
00177     in these quick classes. It handles all index scans of various kinds.
00178   rr_sequential:
00179   --------------
00180     This is the most basic access method of a table using rnd_init,
00181     rnd_next and rnd_end. No indexes are used.
00182 */
00183   int init_read_record(Session *session,
00184                        Table *reg_form,
00185                        optimizer::SqlSelect *select,
00186                        int use_record_cache,
00187                        bool print_errors) __attribute__ ((warn_unused_result));
00188 
00189   void end_read_record();
00190 
00191 
00207   int init_read_record_idx(Session *session,
00208                            Table *table,
00209                            bool print_error,
00210                            uint32_t idx) __attribute__ ((warn_unused_result));
00211 
00212   void init_reard_record_sequential();
00213 
00214   bool init_rr_cache();
00215 };
00216 
00217 } /* namespace drizzled */
00218