~james-page/ubuntu/precise/mysql-5.5/misc-fixes

« back to all changes in this revision

Viewing changes to storage/innobase/handler/ha_innodb.cc

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-06-11 07:34:33 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120611073433-l9za2ni4ipp848y3
Tags: 5.5.24-0ubuntu0.12.04.1
* SECURITY UPDATE: Update to 5.5.24 to fix security issues (LP: #1011371)
  - http://dev.mysql.com/doc/refman/5.5/en/news-5-5-24.html

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
2
 
3
 
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All Rights Reserved.
 
3
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All Rights Reserved.
4
4
Copyright (c) 2008, 2009 Google Inc.
5
5
Copyright (c) 2009, Percona Inc.
6
6
 
998
998
        case DB_OUT_OF_FILE_SPACE:
999
999
                return(HA_ERR_RECORD_FILE_FULL);
1000
1000
 
 
1001
        case DB_TABLE_IN_FK_CHECK:
 
1002
                return(HA_ERR_TABLE_IN_FK_CHECK);
 
1003
 
1001
1004
        case DB_TABLE_IS_BEING_USED:
1002
1005
                return(HA_ERR_WRONG_COMMAND);
1003
1006
 
1447
1450
 
1448
1451
        INSERT INTO T VALUES(), (), ();
1449
1452
 
1450
 
innobase_next_autoinc() will be called with increment set to
1451
 
n * 3 where autoinc_lock_mode != TRADITIONAL because we want
1452
 
to reserve 3 values for the multi-value INSERT above.
 
1453
innobase_next_autoinc() will be called with increment set to 3 where
 
1454
autoinc_lock_mode != TRADITIONAL because we want to reserve 3 values for
 
1455
the multi-value INSERT above.
1453
1456
@return the next value */
1454
1457
static
1455
1458
ulonglong
1456
1459
innobase_next_autoinc(
1457
1460
/*==================*/
1458
1461
        ulonglong       current,        /*!< in: Current value */
1459
 
        ulonglong       increment,      /*!< in: increment current by */
 
1462
        ulonglong       need,           /*!< in: count of values needed */
 
1463
        ulonglong       step,           /*!< in: AUTOINC increment step */
1460
1464
        ulonglong       offset,         /*!< in: AUTOINC offset */
1461
1465
        ulonglong       max_value)      /*!< in: max value for type */
1462
1466
{
1463
1467
        ulonglong       next_value;
 
1468
        ulonglong       block = need * step;
1464
1469
 
1465
1470
        /* Should never be 0. */
1466
 
        ut_a(increment > 0);
 
1471
        ut_a(need > 0);
 
1472
        ut_a(block > 0);
 
1473
        ut_a(max_value > 0);
 
1474
 
 
1475
        /* Current value should never be greater than the maximum. */
 
1476
        ut_a(current <= max_value);
1467
1477
 
1468
1478
        /* According to MySQL documentation, if the offset is greater than
1469
 
        the increment then the offset is ignored. */
1470
 
        if (offset > increment) {
 
1479
        the step then the offset is ignored. */
 
1480
        if (offset > block) {
1471
1481
                offset = 0;
1472
1482
        }
1473
1483
 
1474
 
        if (max_value <= current) {
 
1484
        /* Check for overflow. */
 
1485
        if (block >= max_value
 
1486
            || offset > max_value
 
1487
            || current == max_value
 
1488
            || max_value - offset <= offset) {
 
1489
 
1475
1490
                next_value = max_value;
1476
 
        } else if (offset <= 1) {
1477
 
                /* Offset 0 and 1 are the same, because there must be at
1478
 
                least one node in the system. */
1479
 
                if (max_value - current <= increment) {
 
1491
        } else {
 
1492
                ut_a(max_value > current);
 
1493
 
 
1494
                ulonglong       free = max_value - current;
 
1495
 
 
1496
                if (free < offset || free - offset <= block) {
1480
1497
                        next_value = max_value;
1481
1498
                } else {
1482
 
                        next_value = current + increment;
 
1499
                        next_value = 0;
1483
1500
                }
1484
 
        } else if (max_value > current) {
 
1501
        }
 
1502
 
 
1503
        if (next_value == 0) {
 
1504
                ulonglong       next;
 
1505
 
1485
1506
                if (current > offset) {
1486
 
                        next_value = ((current - offset) / increment) + 1;
 
1507
                        next = (current - offset) / step;
1487
1508
                } else {
1488
 
                        next_value = ((offset - current) / increment) + 1;
 
1509
                        next = (offset - current) / step;
1489
1510
                }
1490
1511
 
1491
 
                ut_a(increment > 0);
1492
 
                ut_a(next_value > 0);
1493
 
 
 
1512
                ut_a(max_value > next);
 
1513
                next_value = next * step;
1494
1514
                /* Check for multiplication overflow. */
1495
 
                if (increment > (max_value / next_value)) {
1496
 
 
1497
 
                        next_value = max_value;
1498
 
                } else {
1499
 
                        next_value *= increment;
1500
 
 
1501
 
                        ut_a(max_value >= next_value);
1502
 
 
1503
 
                        /* Check for overflow. */
1504
 
                        if (max_value - next_value <= offset) {
 
1515
                ut_a(next_value >= next);
 
1516
                ut_a(max_value > next_value);
 
1517
 
 
1518
                /* Check for overflow */
 
1519
                if (max_value - next_value >= block) {
 
1520
 
 
1521
                        next_value += block;
 
1522
 
 
1523
                        if (max_value - next_value >= offset) {
 
1524
                                next_value += offset;
 
1525
                        } else {
1505
1526
                                next_value = max_value;
1506
 
                        } else {
1507
 
                                next_value += offset;
1508
1527
                        }
 
1528
                } else {
 
1529
                        next_value = max_value;
1509
1530
                }
1510
 
        } else {
1511
 
                next_value = max_value;
1512
1531
        }
1513
1532
 
 
1533
        ut_a(next_value != 0);
1514
1534
        ut_a(next_value <= max_value);
1515
1535
 
1516
1536
        return(next_value);
3746
3766
                        nor the offset, so use a default increment of 1. */
3747
3767
 
3748
3768
                        auto_inc = innobase_next_autoinc(
3749
 
                                read_auto_inc, 1, 1, col_max_value);
 
3769
                                read_auto_inc, 1, 1, 0, col_max_value);
3750
3770
 
3751
3771
                        break;
3752
3772
                }
5246
5266
                                if (auto_inc <= col_max_value) {
5247
5267
                                        ut_a(prebuilt->autoinc_increment > 0);
5248
5268
 
5249
 
                                        ulonglong       need;
5250
5269
                                        ulonglong       offset;
 
5270
                                        ulonglong       increment;
5251
5271
 
5252
5272
                                        offset = prebuilt->autoinc_offset;
5253
 
                                        need = prebuilt->autoinc_increment;
 
5273
                                        increment = prebuilt->autoinc_increment;
5254
5274
 
5255
5275
                                        auto_inc = innobase_next_autoinc(
5256
5276
                                                auto_inc,
5257
 
                                                need, offset, col_max_value);
 
5277
                                                1, increment, offset,
 
5278
                                                col_max_value);
5258
5279
 
5259
5280
                                        err = innobase_set_max_autoinc(
5260
5281
                                                auto_inc);
5522
5543
 
5523
5544
                if (auto_inc <= col_max_value && auto_inc != 0) {
5524
5545
 
5525
 
                        ulonglong       need;
5526
5546
                        ulonglong       offset;
 
5547
                        ulonglong       increment;
5527
5548
 
5528
5549
                        offset = prebuilt->autoinc_offset;
5529
 
                        need = prebuilt->autoinc_increment;
 
5550
                        increment = prebuilt->autoinc_increment;
5530
5551
 
5531
5552
                        auto_inc = innobase_next_autoinc(
5532
 
                                auto_inc, need, offset, col_max_value);
 
5553
                                auto_inc, 1, increment, offset, col_max_value);
5533
5554
 
5534
5555
                        error = innobase_set_max_autoinc(auto_inc);
5535
5556
                }
5834
5855
        DBUG_ENTER("index_read");
5835
5856
 
5836
5857
        ut_a(prebuilt->trx == thd_to_trx(user_thd));
 
5858
        ut_ad(key_len != 0 || find_flag != HA_READ_KEY_EXACT);
5837
5859
 
5838
5860
        ha_statistic_increment(&SSV::ha_read_key_count);
5839
5861
 
7003
7025
                DBUG_RETURN(HA_ERR_TO_BIG_ROW);
7004
7026
        }
7005
7027
 
 
7028
        ut_a(strlen(name) < sizeof(name2));
 
7029
 
7006
7030
        strcpy(name2, name);
7007
7031
 
7008
7032
        normalize_table_name(norm_name, name2);
7573
7597
        normalize_table_name(norm_to, to);
7574
7598
        normalize_table_name(norm_from, from);
7575
7599
 
 
7600
        DEBUG_SYNC_C("innodb_rename_table_ready");
 
7601
 
7576
7602
        /* Serialize data dictionary operations with dictionary mutex:
7577
7603
        no deadlocks can occur then in these operations */
7578
7604
 
10137
10163
        /* With old style AUTOINC locking we only update the table's
10138
10164
        AUTOINC counter after attempting to insert the row. */
10139
10165
        if (innobase_autoinc_lock_mode != AUTOINC_OLD_STYLE_LOCKING) {
10140
 
                ulonglong       need;
10141
10166
                ulonglong       current;
10142
10167
                ulonglong       next_value;
10143
10168
 
10144
10169
                current = *first_value > col_max_value ? autoinc : *first_value;
10145
 
                need = *nb_reserved_values * increment;
10146
10170
 
10147
10171
                /* Compute the last value in the interval */
10148
10172
                next_value = innobase_next_autoinc(
10149
 
                        current, need, offset, col_max_value);
 
10173
                        current, *nb_reserved_values, increment, offset,
 
10174
                        col_max_value);
10150
10175
 
10151
10176
                prebuilt->autoinc_last_value = next_value;
10152
10177