[Commits] Rev 2862: Merge MWL#121-125 DS-MRR improvements in file:///home/psergey/dev2/maria-5.3-mwl128-dsmrr-cpk/

Sergey Petrunya psergey at askmonty.org
Thu Nov 25 13:35:23 EET 2010


At file:///home/psergey/dev2/maria-5.3-mwl128-dsmrr-cpk/

------------------------------------------------------------
revno: 2862
revision-id: psergey at askmonty.org-20101125113521-i8vi1jtcoxs1ipr5
parent: psergey at askmonty.org-20101123150811-dmzla6ex8ujhqbu5
committer: Sergey Petrunya <psergey at askmonty.org>
branch nick: maria-5.3-mwl128-dsmrr-cpk
timestamp: Thu 2010-11-25 14:35:21 +0300
message:
  Merge MWL#121-125 DS-MRR improvements 
  - Address Monty's review feedback, part 4
=== modified file 'sql/multi_range_read.cc'
--- a/sql/multi_range_read.cc	2010-11-23 15:08:11 +0000
+++ b/sql/multi_range_read.cc	2010-11-25 11:35:21 +0000
@@ -334,6 +334,7 @@
   
   if (!know_key_tuple_params)
   {
+    //psergey-todo: this will be removed
     /* 
       We're at the very start, haven't filled the buffer or even know what
       will be there. Force the caller to call refill_buffer():
@@ -395,15 +396,18 @@
     buffers for us.
 */
 
-int Mrr_ordered_index_reader::refill_buffer()
+int Mrr_ordered_index_reader::refill_buffer(bool initial)
 {
-  int res;
   KEY_MULTI_RANGE cur_range;
   uchar **range_info_ptr= (uchar**)&cur_range.ptr;
   uchar *key_ptr;
   DBUG_ENTER("Mrr_ordered_index_reader::refill_buffer");
 
   DBUG_ASSERT(!know_key_tuple_params || key_buffer->is_empty());
+
+  if (source_exhausted)
+    DBUG_RETURN(HA_ERR_END_OF_FILE);
+
   if (know_key_tuple_params)
   {
     buf_manager->reset_buffer_sizes();
@@ -414,7 +418,7 @@
   }
 
   while ((!know_key_tuple_params || key_buffer->can_write()) && 
-         !(res= mrr_funcs.next(mrr_iter, &cur_range)))
+         !(source_exhausted= (bool)mrr_funcs.next(mrr_iter, &cur_range)))
   {
     DBUG_ASSERT(cur_range.range_flag & EQ_RANGE);
 
@@ -448,7 +452,7 @@
   /* Force get_next() to start with kv_it.init() call: */
   scanning_key_val_iter= FALSE;
 
-  if (test(res) && (!know_key_tuple_params || key_buffer->is_empty()))
+  if (source_exhausted && (!know_key_tuple_params || key_buffer->is_empty()))
     DBUG_RETURN(HA_ERR_END_OF_FILE);
 
   key_buffer->sort((key_buffer->type() == Lifo_buffer::FORWARD)? 
@@ -469,6 +473,7 @@
   is_mrr_assoc=    !test(mode & HA_MRR_NO_ASSOCIATION);
   mrr_funcs= *seq_funcs;
   know_key_tuple_params= FALSE;
+  source_exhausted= FALSE;
   buf_manager= buf_manager_arg;
   /*
     Short: don't do identical key handling when we have a pushed index
@@ -526,6 +531,7 @@
   rowid_buffer= buf;
   is_mrr_assoc= !test(mode & HA_MRR_NO_ASSOCIATION);
   index_reader_exhausted= FALSE;
+  index_reader_needs_refill= TRUE;
   return 0;
 }
 
@@ -548,7 +554,7 @@
   @retval other  Error
 */
 
-int Mrr_ordered_rndpos_reader::refill_buffer()
+int Mrr_ordered_rndpos_reader::refill_buffer(bool initial)
 {
   int res;
   DBUG_ENTER("Mrr_ordered_rndpos_reader::refill_buffer");
@@ -556,15 +562,17 @@
   if (index_reader_exhausted)
     DBUG_RETURN(HA_ERR_END_OF_FILE);
 
-  while ((res= refill_from_key_buffer()) == HA_ERR_END_OF_FILE)
+  while (initial || index_reader_needs_refill || 
+         (res= refill_from_index_reader()) == HA_ERR_END_OF_FILE)
   {
-    if ((res= index_reader->refill_buffer()))
+    if ((res= index_reader->refill_buffer(initial)))
     {
       if (res == HA_ERR_END_OF_FILE)
         index_reader_exhausted= TRUE;
       break;
     }
-    index_reader_exhausted= FALSE;
+    initial= FALSE;
+    index_reader_needs_refill= FALSE;
   }
   DBUG_RETURN(res);
 }
@@ -581,12 +589,12 @@
   index_reader->refill_buffer(). 
 */
 
-int Mrr_ordered_rndpos_reader::refill_from_key_buffer()
+int Mrr_ordered_rndpos_reader::refill_from_index_reader()
 {
   char *range_info;
   uchar **range_info_ptr= (uchar**)&range_info;
   int res;
-  DBUG_ENTER("Mrr_ordered_rndpos_reader::refill_from_key_buffer");
+  DBUG_ENTER("Mrr_ordered_rndpos_reader::refill_from_index_reader");
 
   DBUG_ASSERT(rowid_buffer->is_empty());
   index_rowid= index_reader->get_rowid_ptr();
@@ -605,7 +613,7 @@
     {
       if (res != HA_ERR_END_OF_FILE)
         DBUG_RETURN(res);
-      index_reader_exhausted= TRUE;     
+      index_reader_needs_refill=TRUE;
       break;
     }
 
@@ -827,7 +835,7 @@
     }
   }
   
-  res= strategy->refill_buffer();
+  res= strategy->refill_buffer(TRUE);
   if (res && res != HA_ERR_END_OF_FILE) //psergey-todo: remove EOF check here
     goto error;
 
@@ -1226,7 +1234,7 @@
   int res;
   while ((res= strategy->get_next(range_info)) == HA_ERR_END_OF_FILE)
   {
-    if ((res= strategy->refill_buffer()))
+    if ((res= strategy->refill_buffer(FALSE)))
       break; /* EOF or error */
   }
   return res;

=== modified file 'sql/multi_range_read.h'
--- a/sql/multi_range_read.h	2010-11-22 16:34:03 +0000
+++ b/sql/multi_range_read.h	2010-11-25 11:35:21 +0000
@@ -189,7 +189,7 @@
 {
 public:
   virtual int get_next(char **range_info) = 0;
-  virtual int refill_buffer() = 0;
+  virtual int refill_buffer(bool initial) = 0;
   virtual ~Mrr_reader() {}; /* just to remove compiler warning */
 };
 
@@ -228,7 +228,7 @@
            void *seq_init_param, uint n_ranges,
            uint mode, Buffer_manager *buf_manager_arg);
   int get_next(char **range_info);
-  int refill_buffer() { return HA_ERR_END_OF_FILE; }
+  int refill_buffer(bool initial) { return initial? 0: HA_ERR_END_OF_FILE; }
   uchar *get_rowid_ptr() { return h->ref; }
   bool skip_record(char *range_id, uchar *rowid)
   {
@@ -249,7 +249,7 @@
            void *seq_init_param, uint n_ranges,
            uint mode, Buffer_manager *buf_manager_arg);
   int get_next(char **range_info);
-  int refill_buffer();
+  int refill_buffer(bool initial);
   uchar *get_rowid_ptr() { return h->ref; }
   
   bool skip_record(char *range_info, uchar *rowid)
@@ -298,6 +298,9 @@
   /* Range sequence iteration members */
   RANGE_SEQ_IF mrr_funcs;
   range_seq_t mrr_iter;
+  
+  /* TRUE == reached eof when enumerating ranges */
+  bool source_exhausted;
 
   static int compare_keys(void* arg, uchar* key1, uchar* key2);
   static int compare_keys_reverse(void* arg, uchar* key1, uchar* key2);
@@ -319,7 +322,7 @@
   int init(handler *h, Mrr_index_reader *index_reader, uint mode,
            Lifo_buffer *buf);
   int get_next(char **range_info);
-  int refill_buffer();
+  int refill_buffer(bool initial);
 private:
   handler *h; /* Handler to use */
   
@@ -332,6 +335,7 @@
   /* TRUE <=> index_reader->refill_buffer() call has returned EOF */
   bool index_reader_exhausted;
   
+  bool index_reader_needs_refill;
   /* TRUE <=> need range association, buffers hold {rowid, range_id} pairs */
   bool is_mrr_assoc;
   
@@ -348,7 +352,7 @@
   uchar *rowid;
   uchar *rowids_range_id;
 
-  int refill_from_key_buffer();
+  int refill_from_index_reader();
 };
 
 



More information about the commits mailing list