~ubuntu-branches/ubuntu/raring/mysql-5.5/raring-proposed

« back to all changes in this revision

Viewing changes to sql/opt_range.cc

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2013-01-16 08:29:25 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20130116082925-znscu5xswxo6pmw2
Tags: 5.5.29-0ubuntu1
* SECURITY UPDATE: Update to 5.5.29 to fix security issues (LP: #1100264)
  - http://www.oracle.com/technetwork/topics/security/cpujan2013-1515902.html
* debian/patches/CVE-2012-5611.patch: removed, included upstream.
* debian/patches/38_scripts__mysqld_safe.sh__signals.patch: refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
#include "records.h"          // init_read_record, end_read_record
75
75
#include <m_ctype.h>
76
76
#include "sql_select.h"
 
77
#include "filesort.h"         // filesort_free_buffers
77
78
 
78
79
#ifndef EXTRA_DEBUG
79
80
#define test_rb_tree(A,B) {}
1182
1183
{
1183
1184
  DBUG_ENTER("QUICK_RANGE_SELECT::init");
1184
1185
 
1185
 
  if (file->inited != handler::NONE)
 
1186
  if (file->inited)
1186
1187
    file->ha_index_or_rnd_end();
1187
1188
  DBUG_RETURN(FALSE);
1188
1189
}
1190
1191
 
1191
1192
void QUICK_RANGE_SELECT::range_end()
1192
1193
{
1193
 
  if (file->inited != handler::NONE)
 
1194
  if (file->inited)
1194
1195
    file->ha_index_or_rnd_end();
1195
1196
}
1196
1197
 
1246
1247
int QUICK_INDEX_MERGE_SELECT::reset()
1247
1248
{
1248
1249
  DBUG_ENTER("QUICK_INDEX_MERGE_SELECT::reset");
1249
 
  DBUG_RETURN(read_keys_and_merge());
 
1250
  const int retval= read_keys_and_merge();
 
1251
  DBUG_RETURN(retval);
1250
1252
}
1251
1253
 
1252
1254
bool
1448
1450
      There is no use of this->file. Use it for the first of merged range
1449
1451
      selects.
1450
1452
    */
1451
 
    if (quick->init_ror_merged_scan(TRUE))
1452
 
      DBUG_RETURN(1);
 
1453
    int error= quick->init_ror_merged_scan(TRUE);
 
1454
    if (error)
 
1455
      DBUG_RETURN(error);
1453
1456
    quick->file->extra(HA_EXTRA_KEYREAD_PRESERVE_FIELDS);
1454
1457
  }
1455
1458
  while ((quick= quick_it++))
1520
1523
  quick_selects.delete_elements();
1521
1524
  delete cpk_quick;
1522
1525
  free_root(&alloc,MYF(0));
1523
 
  if (need_to_fetch_row && head->file->inited != handler::NONE)
 
1526
  if (need_to_fetch_row && head->file->inited)
1524
1527
    head->file->ha_rnd_end();
1525
1528
  DBUG_VOID_RETURN;
1526
1529
}
1624
1627
  List_iterator_fast<QUICK_SELECT_I> it(quick_selects);
1625
1628
  while ((quick= it++))
1626
1629
  {
1627
 
    if (quick->reset())
1628
 
      DBUG_RETURN(1);
 
1630
    if ((error= quick->reset()))
 
1631
      DBUG_RETURN(error);
1629
1632
    if ((error= quick->get_next()))
1630
1633
    {
1631
1634
      if (error == HA_ERR_END_OF_FILE)
1636
1639
    queue_insert(&queue, (uchar*)quick);
1637
1640
  }
1638
1641
 
1639
 
  if (head->file->ha_rnd_init(1))
 
1642
  if ((error= head->file->ha_rnd_init(1)))
1640
1643
  {
1641
1644
    DBUG_PRINT("error", ("ROR index_merge rnd_init call failed"));
1642
 
    DBUG_RETURN(1);
 
1645
    DBUG_RETURN(error);
1643
1646
  }
1644
1647
 
1645
1648
  DBUG_RETURN(0);
1657
1660
  DBUG_ENTER("QUICK_ROR_UNION_SELECT::~QUICK_ROR_UNION_SELECT");
1658
1661
  delete_queue(&queue);
1659
1662
  quick_selects.delete_elements();
1660
 
  if (head->file->inited != handler::NONE)
 
1663
  if (head->file->inited)
1661
1664
    head->file->ha_rnd_end();
1662
1665
  free_root(&alloc,MYF(0));
1663
1666
  DBUG_VOID_RETURN;
8295
8298
                       thd->variables.sortbuff_size);
8296
8299
  }
8297
8300
  else
 
8301
  {
8298
8302
    unique->reset();
 
8303
    filesort_free_buffers(head, false);
 
8304
  }
8299
8305
 
8300
8306
  DBUG_ASSERT(file->ref_length == unique->get_size());
8301
8307
  DBUG_ASSERT(thd->variables.sortbuff_size == unique->get_max_in_memory_size());
8311
8317
      if (!cur_quick)
8312
8318
        break;
8313
8319
 
8314
 
      if (cur_quick->file->inited != handler::NONE) 
 
8320
      if (cur_quick->file->inited)
8315
8321
        cur_quick->file->ha_index_end();
8316
8322
      if (cur_quick->init() || cur_quick->reset())
8317
8323
        DBUG_RETURN(1);
8406
8412
    If a Clustered PK scan is present, it is used only to check if row
8407
8413
    satisfies its condition (and never used for row retrieval).
8408
8414
 
 
8415
    Locking: to ensure that exclusive locks are only set on records that
 
8416
    are included in the final result we must release the lock
 
8417
    on all rows we read but do not include in the final result. This
 
8418
    must be done on each index that reads the record and the lock
 
8419
    must be released using the same handler (the same quick object) as
 
8420
    used when reading the record.
 
8421
 
8409
8422
  RETURN
8410
8423
   0     - Ok
8411
8424
   other - Error code if any error occurred.
8415
8428
{
8416
8429
  List_iterator_fast<QUICK_RANGE_SELECT> quick_it(quick_selects);
8417
8430
  QUICK_RANGE_SELECT* quick;
 
8431
 
 
8432
  /* quick that reads the given rowid first. This is needed in order
 
8433
  to be able to unlock the row using the same handler object that locked
 
8434
  it */
 
8435
  QUICK_RANGE_SELECT* quick_with_last_rowid;
 
8436
 
8418
8437
  int error, cmp;
8419
8438
  uint last_rowid_count=0;
8420
8439
  DBUG_ENTER("QUICK_ROR_INTERSECT_SELECT::get_next");
8427
8446
    if (cpk_quick)
8428
8447
    {
8429
8448
      while (!error && !cpk_quick->row_in_ranges())
 
8449
      {
 
8450
        quick->file->unlock_row(); /* row not in range; unlock */
8430
8451
        error= quick->get_next();
 
8452
      }
8431
8453
    }
8432
8454
    if (error)
8433
8455
      DBUG_RETURN(error);
8435
8457
    quick->file->position(quick->record);
8436
8458
    memcpy(last_rowid, quick->file->ref, head->file->ref_length);
8437
8459
    last_rowid_count= 1;
 
8460
    quick_with_last_rowid= quick;
8438
8461
 
8439
8462
    while (last_rowid_count < quick_selects.elements)
8440
8463
    {
8447
8470
      do
8448
8471
      {
8449
8472
        if ((error= quick->get_next()))
 
8473
        {
 
8474
          quick_with_last_rowid->file->unlock_row();
8450
8475
          DBUG_RETURN(error);
 
8476
        }
8451
8477
        quick->file->position(quick->record);
8452
8478
        cmp= head->file->cmp_ref(quick->file->ref, last_rowid);
 
8479
        if (cmp < 0)
 
8480
        {
 
8481
          /* This row is being skipped.  Release lock on it. */
 
8482
          quick->file->unlock_row();
 
8483
        }
8453
8484
      } while (cmp < 0);
8454
8485
 
8455
8486
      /* Ok, current select 'caught up' and returned ref >= cur_ref */
8460
8491
        {
8461
8492
          while (!cpk_quick->row_in_ranges())
8462
8493
          {
 
8494
            quick->file->unlock_row(); /* row not in range; unlock */
8463
8495
            if ((error= quick->get_next()))
 
8496
            {
 
8497
              quick_with_last_rowid->file->unlock_row();
8464
8498
              DBUG_RETURN(error);
 
8499
            }
8465
8500
          }
8466
8501
          quick->file->position(quick->record);
8467
8502
        }
8468
8503
        memcpy(last_rowid, quick->file->ref, head->file->ref_length);
 
8504
        quick_with_last_rowid->file->unlock_row();
8469
8505
        last_rowid_count= 1;
 
8506
        quick_with_last_rowid= quick;
8470
8507
      }
8471
8508
      else
8472
8509
      {
8563
8600
  {
8564
8601
    if (in_ror_merged_scan)
8565
8602
      head->column_bitmaps_set_no_signal(&column_bitmap, &column_bitmap);
 
8603
 
 
8604
    DBUG_EXECUTE_IF("bug14365043_2",
 
8605
                    DBUG_SET("+d,ha_index_init_fail"););
8566
8606
    if ((error= file->ha_index_init(index,1)))
 
8607
    {
 
8608
        file->print_error(error, MYF(0));
8567
8609
        DBUG_RETURN(error);
 
8610
    }
8568
8611
  }
8569
8612
 
8570
8613
  /* Do not allocate the buffers twice. */
10778
10821
 
10779
10822
  head->set_keyread(TRUE); /* We need only the key attributes */
10780
10823
  if ((result= file->ha_index_init(index,1)))
 
10824
  {
 
10825
    head->file->print_error(result, MYF(0));
10781
10826
    DBUG_RETURN(result);
 
10827
  }
10782
10828
  if (quick_prefix_select && quick_prefix_select->reset())
10783
10829
    DBUG_RETURN(1);
10784
10830
  result= file->index_last(record);