Skip to content

Commit 7e764ae

Browse files
committed
SQL: 1-row partition rotation fix [fixes #260]
1 parent 78d2430 commit 7e764ae

File tree

7 files changed

+46
-15
lines changed

7 files changed

+46
-15
lines changed

include/my_base.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ enum ha_base_keytype {
407407
when only HA_STATUS_VARIABLE but it won't be used.
408408
*/
409409
#define HA_STATUS_VARIABLE_EXTRA 128U
410+
/*
411+
Treat empty table as empty (ignore HA_STATUS_TIME hack).
412+
*/
413+
#define HA_STATUS_OPEN 256U
410414

411415
/*
412416
Errorcodes given by handler functions

mysql-test/suite/versioning/r/partition.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ x
159159
2
160160
create or replace table t1 (x int)
161161
with system versioning
162+
partition by system_time limit 1 (
163+
partition p0 versioning,
164+
partition pn as of now);
165+
alter table t1 change x big int;
166+
create or replace table t1 (x int)
167+
with system versioning
162168
partition by system_time (
163169
partition p0 versioning,
164170
partition pn as of now);

mysql-test/suite/versioning/t/partition.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ alter table t1 drop partition p0;
8989

9090
select x from t1;
9191

92+
# Bug #260: incorrect IB partitioning warning
93+
create or replace table t1 (x int)
94+
with system versioning
95+
partition by system_time limit 1 (
96+
partition p0 versioning,
97+
partition pn as of now);
98+
alter table t1 change x big int;
99+
92100
# insert, delete, update
93101
create or replace table t1 (x int)
94102
with system versioning

sql/ha_partition.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3550,7 +3550,7 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked)
35503550
m_part_info->part_expr->get_monotonicity_info();
35513551
else if (m_part_info->list_of_part_fields)
35523552
m_part_func_monotonicity_info= MONOTONIC_STRICT_INCREASING;
3553-
info(HA_STATUS_VARIABLE | HA_STATUS_CONST);
3553+
info(HA_STATUS_OPEN | HA_STATUS_VARIABLE | HA_STATUS_CONST);
35543554
DBUG_RETURN(0);
35553555

35563556
err_handler:
@@ -6550,6 +6550,7 @@ int ha_partition::info(uint flag)
65506550
{
65516551
uint no_lock_flag= flag & HA_STATUS_NO_LOCK;
65526552
uint extra_var_flag= flag & HA_STATUS_VARIABLE_EXTRA;
6553+
uint open_flag= flag & HA_STATUS_OPEN;
65536554
DBUG_ENTER("ha_partition::info");
65546555

65556556
#ifndef DBUG_OFF
@@ -6590,7 +6591,7 @@ int ha_partition::info(uint flag)
65906591
do
65916592
{
65926593
file= *file_array;
6593-
file->info(HA_STATUS_AUTO | no_lock_flag);
6594+
file->info(HA_STATUS_AUTO | no_lock_flag | open_flag);
65946595
set_if_bigger(auto_increment_value,
65956596
file->stats.auto_increment_value);
65966597
} while (*(++file_array));
@@ -6644,7 +6645,7 @@ int ha_partition::info(uint flag)
66446645
i= bitmap_get_next_set(&m_part_info->read_partitions, i))
66456646
{
66466647
file= m_file[i];
6647-
file->info(HA_STATUS_VARIABLE | no_lock_flag | extra_var_flag);
6648+
file->info(HA_STATUS_VARIABLE | no_lock_flag | extra_var_flag | open_flag);
66486649
stats.records+= file->stats.records;
66496650
stats.deleted+= file->stats.deleted;
66506651
stats.data_file_length+= file->stats.data_file_length;
@@ -6725,7 +6726,7 @@ int ha_partition::info(uint flag)
67256726
if (!(flag & HA_STATUS_VARIABLE) ||
67266727
!bitmap_is_set(&(m_part_info->read_partitions),
67276728
(file_array - m_file)))
6728-
file->info(HA_STATUS_VARIABLE | no_lock_flag | extra_var_flag);
6729+
file->info(HA_STATUS_VARIABLE | no_lock_flag | extra_var_flag | open_flag);
67296730
if (file->stats.records > max_records)
67306731
{
67316732
max_records= file->stats.records;
@@ -6744,7 +6745,7 @@ int ha_partition::info(uint flag)
67446745
this);
67456746

67466747
file= m_file[handler_instance];
6747-
file->info(HA_STATUS_CONST | no_lock_flag);
6748+
file->info(HA_STATUS_CONST | no_lock_flag | open_flag);
67486749
stats.block_size= file->stats.block_size;
67496750
stats.create_time= file->stats.create_time;
67506751
ref_length= m_ref_length;
@@ -6760,7 +6761,7 @@ int ha_partition::info(uint flag)
67606761
Note: all engines does not support HA_STATUS_ERRKEY, so set errkey.
67616762
*/
67626763
file->errkey= errkey;
6763-
file->info(HA_STATUS_ERRKEY | no_lock_flag);
6764+
file->info(HA_STATUS_ERRKEY | no_lock_flag | open_flag);
67646765
errkey= file->errkey;
67656766
}
67666767
if (flag & HA_STATUS_TIME)
@@ -6777,7 +6778,7 @@ int ha_partition::info(uint flag)
67776778
do
67786779
{
67796780
file= *file_array;
6780-
file->info(HA_STATUS_TIME | no_lock_flag);
6781+
file->info(HA_STATUS_TIME | no_lock_flag | open_flag);
67816782
if (file->stats.update_time > stats.update_time)
67826783
stats.update_time= file->stats.update_time;
67836784
} while (*(++file_array));

sql/ha_partition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ class ha_partition :public handler
13681368
{
13691369
handler *file= m_file[part_id];
13701370
DBUG_ASSERT(bitmap_is_set(&(m_part_info->read_partitions), part_id));
1371-
file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
1371+
file->info(HA_STATUS_OPEN | HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
13721372
part_recs+= file->stats.records;
13731373
}
13741374
return part_recs;

sql/sql_partition.cc

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3426,11 +3426,21 @@ int vers_get_partition_id(partition_info *part_info,
34263426
DBUG_ASSERT(part_info);
34273427
Field *sys_trx_end= part_info->part_field_array[STAT_TRX_END];
34283428
DBUG_ASSERT(sys_trx_end);
3429-
DBUG_ASSERT(part_info->table);
3429+
TABLE *table= part_info->table;
3430+
DBUG_ASSERT(table);
34303431
Vers_part_info *vers_info= part_info->vers_info;
3431-
DBUG_ASSERT(vers_info && vers_info->initialized());
3432-
DBUG_ASSERT(sys_trx_end->table == part_info->table && part_info->table->versioned());
3433-
DBUG_ASSERT(part_info->table->vers_end_field() == sys_trx_end);
3432+
DBUG_ASSERT(vers_info);
3433+
DBUG_ASSERT(vers_info->initialized());
3434+
DBUG_ASSERT(sys_trx_end->table == table);
3435+
bool tmp_off= false;
3436+
if (!table->versioned() && table->file->native_versioned())
3437+
{
3438+
// in copy_data_between_tables() versioning may be temporarily turned off
3439+
tmp_off= true;
3440+
table->s->versioned= true;
3441+
}
3442+
DBUG_ASSERT(table->versioned());
3443+
DBUG_ASSERT(table->vers_end_field() == sys_trx_end);
34343444

34353445
// new rows have NULL in sys_trx_end
34363446
if (sys_trx_end->is_max() || sys_trx_end->is_null())
@@ -3440,7 +3450,6 @@ int vers_get_partition_id(partition_info *part_info,
34403450
else // row is historical
34413451
{
34423452
THD *thd= current_thd;
3443-
TABLE *table= part_info->table;
34443453

34453454
switch (thd->lex->sql_command)
34463455
{
@@ -3478,6 +3487,9 @@ int vers_get_partition_id(partition_info *part_info,
34783487
*part_id= vers_info->hist_part->id;
34793488
}
34803489

3490+
if (tmp_off)
3491+
table->s->versioned= false;
3492+
34813493
DBUG_PRINT("exit",("partition: %d", *part_id));
34823494
DBUG_RETURN(0);
34833495
}

storage/innobase/handler/ha_innodb.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6862,7 +6862,7 @@ ha_innobase::open(
68626862
}
68636863
}
68646864

6865-
info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
6865+
info(HA_STATUS_OPEN | HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST);
68666866
DBUG_RETURN(0);
68676867
}
68686868

@@ -14958,7 +14958,7 @@ ha_innobase::info_low(
1495814958
set. That way SHOW TABLE STATUS will show the best estimate,
1495914959
while the optimizer never sees the table empty. */
1496014960

14961-
if (n_rows == 0 && !(flag & HA_STATUS_TIME)) {
14961+
if (n_rows == 0 && !(flag & (HA_STATUS_TIME | HA_STATUS_OPEN))) {
1496214962
n_rows++;
1496314963
}
1496414964

0 commit comments

Comments
 (0)