Skip to content

Commit

Permalink
Vers IB: Mark unversioned fields in system versioning tables
Browse files Browse the repository at this point in the history
Some fields in system-versioned table may be unversioned.
SQL layer marks unversioned.
And this patch makes InnoDB mark unversioned too because of two reasons:
1) by default fields are versioned
2) most of fields are expected to be versioned

dtype_t::vers_sys_field(): fixed return true on row_start/row_end
dict_col_t::vers_sys_field(): fixed return true on row_start/row_end
  • Loading branch information
kevgs committed Mar 19, 2018
1 parent 0cf97ad commit fd73c6d
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 28 deletions.
17 changes: 9 additions & 8 deletions storage/innobase/dict/dict0mem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,15 @@ dict_mem_table_add_col(

dict_mem_fill_column_struct(col, i, mtype, prtype, len);

switch (prtype & DATA_VERSIONED) {
case DATA_VERS_START:
ut_ad(!table->vers_start);
table->vers_start = i;
break;
case DATA_VERS_END:
ut_ad(!table->vers_end);
table->vers_end = i;
if ((prtype & DATA_UNVERSIONED) != DATA_UNVERSIONED) {
if (prtype & DATA_VERS_START) {
ut_ad(!table->vers_start);
table->vers_start = i;
}
if (prtype & DATA_VERS_END) {
ut_ad(!table->vers_end);
table->vers_end = i;
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11265,9 +11265,9 @@ create_table_info_t::create_table_def()
vers_row = DATA_VERS_START;
} else if (i == m_form->s->row_end_field) {
vers_row = DATA_VERS_END;
} else if (!(field->flags
& VERS_UPDATE_UNVERSIONED_FLAG)) {
vers_row = DATA_VERSIONED;
} else if (field->flags
& VERS_UPDATE_UNVERSIONED_FLAG) {
vers_row = DATA_UNVERSIONED;
}
}

Expand Down
6 changes: 3 additions & 3 deletions storage/innobase/handler/handler0alter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5009,9 +5009,9 @@ prepare_inplace_alter_table_dict(
} else if (i ==
altered_table->s->row_end_field) {
field_type |= DATA_VERS_END;
} else if (!(field->flags
& VERS_UPDATE_UNVERSIONED_FLAG)) {
field_type |= DATA_VERSIONED;
} else if (field->flags
& VERS_UPDATE_UNVERSIONED_FLAG) {
field_type |= DATA_UNVERSIONED;
}
}

Expand Down
14 changes: 8 additions & 6 deletions storage/innobase/include/data0type.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ be less than 256 */
/** System Versioning */
#define DATA_VERS_START 16384U /* start system field */
#define DATA_VERS_END 32768U /* end system field */
/** system-versioned user data column */
#define DATA_VERSIONED (DATA_VERS_START|DATA_VERS_END)
#define DATA_UNVERSIONED (DATA_VERS_START|DATA_VERS_END) /* unversioned user field */

/** Check whether locking is disabled (never). */
#define dict_table_is_locking_disabled(table) false
Expand Down Expand Up @@ -543,18 +542,21 @@ struct dtype_t{
in bytes */

/** @return whether this is system field */
bool vers_sys_field() const { return prtype & DATA_VERSIONED; }
bool vers_sys_field() const
{
return vers_sys_start() || vers_sys_end();
}
/** @return whether this is system versioned user field */
bool is_versioned() const { return !(~prtype & DATA_VERSIONED); }
bool is_versioned() const { return (prtype & DATA_UNVERSIONED) == 0; }
/** @return whether this is the system field start */
bool vers_sys_start() const
{
return (prtype & DATA_VERSIONED) == DATA_VERS_START;
return (prtype & DATA_UNVERSIONED) == DATA_VERS_START;
}
/** @return whether this is the system field end */
bool vers_sys_end() const
{
return (prtype & DATA_VERSIONED) == DATA_VERS_END;
return (prtype & DATA_UNVERSIONED) == DATA_VERS_END;
}
};

Expand Down
11 changes: 7 additions & 4 deletions storage/innobase/include/dict0mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,10 @@ struct dict_col_t{
bool is_nullable() const { return !(prtype & DATA_NOT_NULL); }

/** @return whether this is system field */
bool vers_sys_field() const { return prtype & DATA_VERSIONED; }
bool vers_sys_field() const
{
return vers_sys_start() || vers_sys_end();
}
/** @return whether table of this system field is TRX_ID-based */
bool vers_native() const
{
Expand All @@ -662,16 +665,16 @@ struct dict_col_t{
return mtype == DATA_INT;
}
/** @return whether this is system versioned */
bool is_versioned() const { return !(~prtype & DATA_VERSIONED); }
bool is_versioned() const { return (prtype & DATA_UNVERSIONED) == 0; }
/** @return whether this is the system version start */
bool vers_sys_start() const
{
return (prtype & DATA_VERSIONED) == DATA_VERS_START;
return (prtype & DATA_UNVERSIONED) == DATA_VERS_START;
}
/** @return whether this is the system version end */
bool vers_sys_end() const
{
return (prtype & DATA_VERSIONED) == DATA_VERS_END;
return (prtype & DATA_UNVERSIONED) == DATA_VERS_END;
}

/** @return whether this is an instantly-added column */
Expand Down
9 changes: 7 additions & 2 deletions storage/innobase/include/row0upd.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,16 @@ struct upd_t{
return(false);
}

/** Determine if the update affects a system versioned column. */
/** Determine if the update affects a system versioned column or row_end. */
bool affects_versioned() const
{
for (ulint i = 0; i < n_fields; i++) {
if (fields[i].new_val.type.vers_sys_field()) {
dtype_t type = fields[i].new_val.type;
if (type.is_versioned()) {
return true;
}
// versioned DELETE is UPDATE SET row_end=NOW
if (type.vers_sys_end()) {
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/trx/trx0rec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2089,8 +2089,8 @@ trx_undo_report_row_operation(
if (!time.is_versioned()
&& index->table->versioned_by_id()
&& (!rec /* INSERT */
|| !update /* DELETE */
|| update->affects_versioned())) {
|| (update
&& update->affects_versioned()))) {
time.set_versioned(limit);
}
}
Expand Down

0 comments on commit fd73c6d

Please sign in to comment.