diff -Narup ./036_mariadb-10.0.15-minus_sign_variables/sql/ha_partition.cc ./037_mariadb-10.0.15-partition_bka/sql/ha_partition.cc
--- ./036_mariadb-10.0.15-minus_sign_variables/sql/ha_partition.cc	2014-11-29 17:08:10.842795689 +0900
+++ ./037_mariadb-10.0.15-partition_bka/sql/ha_partition.cc	2014-11-29 17:08:41.168796738 +0900
@@ -5659,6 +5659,7 @@ bool ha_partition::init_record_priority_
       cmp_func= cmp_key_part_id;
       cmp_arg= (void*)m_curr_key_info;
     }
+    DBUG_PRINT("info", ("partition queue_init(1) used_parts=%u", used_parts));
     if (init_queue(&m_queue, used_parts, 0, 0, cmp_func, cmp_arg, 0, 0))
     {
       my_free(m_ordered_rec_buffer);
@@ -7741,6 +7742,7 @@ int ha_partition::handle_ordered_index_s
     bitmap_clear_all(&m_key_not_found_partitions);
   }
   m_top_entry= NO_CURRENT_PART_ID;
+  DBUG_PRINT("info", ("partition queue_remove_all(1)"));
   queue_remove_all(&m_queue);
   DBUG_ASSERT(bitmap_is_set(&m_part_info->read_partitions,
                             m_part_spec.start_part));
@@ -7803,7 +7805,9 @@ int ha_partition::handle_ordered_index_s
         part_rec_buf_ptr+= m_rec_length + PARTITION_BYTES_IN_POS;
         continue;
       }
+      DBUG_PRINT("info", ("partition %u", i));
       error = file->multi_range_read_next(&m_range_info[i]);
+      DBUG_PRINT("info", ("error=%d", error));
       if (error == HA_ERR_KEY_NOT_FOUND || error == HA_ERR_END_OF_FILE)
       {
         bitmap_clear_bit(&m_mrr_used_partitions, i);
@@ -7869,9 +7873,16 @@ int ha_partition::handle_ordered_index_s
     for (i = m_part_spec.start_part; i <= m_part_spec.end_part; i++)
     {
       if (!(bitmap_is_set(&(m_part_info->read_partitions), i)))
+      {
+        part_rec_buf_ptr+= m_rec_length + PARTITION_BYTES_IN_POS;
         continue;
+      }
       if (!bitmap_is_set(&m_mrr_used_partitions, i))
+      {
+        part_rec_buf_ptr+= m_rec_length + PARTITION_BYTES_IN_POS;
         continue;
+      }
+      DBUG_ASSERT(i == uint2korr(part_rec_buf_ptr));
       if (smallest_range_seq == m_stock_range_seq[i])
       {
         m_stock_range_seq[i] = 0;
@@ -7970,8 +7981,10 @@ int ha_partition::handle_ordered_index_s
       /* HA_ERR_KEY_NOT_FOUND is not allowed from index_next! */
       DBUG_ASSERT(error != HA_ERR_KEY_NOT_FOUND);
       if (!error)
+      {
+        DBUG_PRINT("info", ("partition queue_insert(1)"));
         queue_insert(&m_queue, part_buf);
-      else if (error != HA_ERR_END_OF_FILE && error != HA_ERR_KEY_NOT_FOUND)
+      } else if (error != HA_ERR_END_OF_FILE && error != HA_ERR_KEY_NOT_FOUND)
         DBUG_RETURN(error);
     }
     part_buf += m_priority_queue_rec_len;
@@ -8057,38 +8070,48 @@ int ha_partition::handle_ordered_next(uc
   }
   else if (m_index_scan_type == partition_read_multi_range)
   {
+    DBUG_PRINT("info", ("partition_read_multi_range route"));
+    DBUG_PRINT("info", ("part_id=%u", part_id));
     bool get_next = FALSE;
     error = file->multi_range_read_next(&m_range_info[part_id]);
     if (error == HA_ERR_KEY_NOT_FOUND)
       error = HA_ERR_END_OF_FILE;
+    DBUG_PRINT("info", ("error=%d", error));
     if (error == HA_ERR_END_OF_FILE)
     {
       bitmap_clear_bit(&m_mrr_used_partitions, part_id);
-      queue_remove(&m_queue, (uint) 0);
+      DBUG_PRINT("info", ("partition queue_remove_top(1)"));
+      queue_remove_top(&m_queue);
       if (!m_queue.elements)
         get_next = TRUE;
       else {
-        DBUG_PRINT("info", ("Record returned from partition %u (3)",
-          m_top_entry));
         return_top_record(buf);
         table->status = 0;
+        DBUG_PRINT("info", ("Record returned from partition %u (3)",
+          m_top_entry));
         DBUG_RETURN(0);
       }
     } else if (!error)
     {
+      DBUG_PRINT("info", ("m_range_info[%u])->id=%u", part_id,
+        ((PARTITION_KEY_MULTI_RANGE *) m_range_info[part_id])->id));
+      DBUG_PRINT("info", ("m_mrr_range_current->id=%u",
+        m_mrr_range_current->id));
       memcpy(rec_buf, table->record[0], m_rec_length);
       if (((PARTITION_KEY_MULTI_RANGE *) m_range_info[part_id])->id !=
         m_mrr_range_current->id)
       {
         m_stock_range_seq[part_id]=
           ((PARTITION_KEY_MULTI_RANGE *) m_range_info[part_id])->id;
-        queue_remove(&m_queue, (uint) 0);
+        DBUG_PRINT("info", ("partition queue_remove_top(2)"));
+        queue_remove_top(&m_queue);
         if (!m_queue.elements)
           get_next = TRUE;
       }
     }
     if (get_next)
     {
+      DBUG_PRINT("info", ("get_next route"));
       uint i, j = 0, smallest_range_seq = 0;
       for (i = m_part_spec.start_part; i <= m_part_spec.end_part; i++)
       {
@@ -8104,20 +8127,35 @@ int ha_partition::handle_ordered_next(uc
         }
       }
 
+      DBUG_PRINT("info", ("smallest_range_seq=%u", smallest_range_seq));
       if (smallest_range_seq)
       {
         uchar *part_rec_buf_ptr= m_ordered_rec_buffer;
+        DBUG_PRINT("info", ("partition queue_remove_all(2)"));
         queue_remove_all(&m_queue);
+        DBUG_PRINT("info", ("m_part_spec.start_part=%u",
+          m_part_spec.start_part));
         for (i = m_part_spec.start_part; i <= m_part_spec.end_part; i++)
         {
           if (!(bitmap_is_set(&(m_part_info->read_partitions), i)))
+          {
+            part_rec_buf_ptr+= m_rec_length + PARTITION_BYTES_IN_POS;
             continue;
+          }
           if (!bitmap_is_set(&m_mrr_used_partitions, i))
+          {
+            part_rec_buf_ptr+= m_rec_length + PARTITION_BYTES_IN_POS;
             continue;
+          }
+          DBUG_ASSERT(i == uint2korr(part_rec_buf_ptr));
+          DBUG_PRINT("info", ("m_stock_range_seq[%u]=%u",
+            i, m_stock_range_seq[i]));
           if (smallest_range_seq == m_stock_range_seq[i])
           {
             m_stock_range_seq[i] = 0;
-            queue_element(&m_queue, j++) = part_rec_buf_ptr;
+            DBUG_PRINT("info", ("partition queue_insert(2)"));
+            queue_insert(&m_queue, part_rec_buf_ptr);
+            j++;
           }
           part_rec_buf_ptr+= m_rec_length + PARTITION_BYTES_IN_POS;
         }
@@ -8129,10 +8167,10 @@ int ha_partition::handle_ordered_next(uc
         queue_set_cmp_arg(&m_queue, (void *) m_curr_key_info);
         m_queue.elements = j;
         queue_fix(&m_queue);
-        DBUG_PRINT("info", ("Record returned from partition %u (4)",
-          m_top_entry));
         return_top_record(buf);
         table->status = 0;
+        DBUG_PRINT("info", ("Record returned from partition %u (4)",
+          m_top_entry));
         DBUG_RETURN(0);
       }
     }
@@ -8153,13 +8191,14 @@ int ha_partition::handle_ordered_next(uc
     if (error == HA_ERR_END_OF_FILE && m_queue.elements)
     {
       /* Return next buffered row */
+      DBUG_PRINT("info", ("partition queue_remove_top(3)"));
       queue_remove_top(&m_queue);
       if (m_queue.elements)
       {
-         DBUG_PRINT("info", ("Record returned from partition %u (2)",
-                     m_top_entry));
          return_top_record(buf);
          table->status= 0;
+         DBUG_PRINT("info", ("Record returned from partition %u (2)",
+                     m_top_entry));
          error= 0;
       }
     }
@@ -8206,6 +8245,7 @@ int ha_partition::handle_ordered_prev(uc
   {
     if (error == HA_ERR_END_OF_FILE && m_queue.elements)
     {
+      DBUG_PRINT("info", ("partition queue_remove_top(4)"));
       queue_remove_top(&m_queue);
       if (m_queue.elements)
       {
