Commit graph

324 commits

Author SHA1 Message Date
Eugene Kosov
b5184c7efb MDEV-15947 ASAN heap-use-after-free in Item_ident::print or in my_strcasecmp_utf8 or unexpected ER_BAD_FIELD_ERROR upon call of stored procedure reading from versioned table
Closes #728
2018-06-30 16:12:36 +02:00
Eugene Kosov
133cfe39f1 MDEV-15645 Assertion `table->insert_values' failed in write_record upon REPLACE into a view with underlying versioned table
Right temporary storage for system versioning operations is table->record[2],
not table->insert_values

Closes #712
2018-06-30 16:12:28 +02:00
Eugene Kosov
9dc81f7d38 MDEV-16330 Allow instant change of WITH SYSTEM VERSIONING column attribute
Changing columns WITH/WITHOUT SYSTEM VERSIONING doens't require to read data at
all. Thus it should be an instant operation.

Patch also fixes a bug when ALTER_COLUMN_UNVERSIONED wasn't passed to InnoDB
to change its internal structures.

change_field_versioning_try(): apply WITH/WITHOUT SYSTEM VERSIONING
change in SYS_COLUMNS for one field.

change_fields_versioning_try(): apply WITH/WITHOUT SYSTEM VERSIONING
change in SYS_COLUMNS for every changed field in a table.

change_fields_versioning_cache(): update cache for versioning property
of columns.
2018-06-20 19:23:48 +03:00
Eugene Kosov
748ef3ec91 MDEV-15991 Server crashes in setup_on_expr upon calling SP or function executing DML on versioned tables
Do not try to set versioning conditions on every SP call. It may work
incorrectly, but it's a general bug described in MDEV-774.
This patch makes system versioning stuff consistent with other code and
also fixes a use-after-free bug.

Closes #756
2018-06-03 23:25:43 +02:00
Aleksey Midenkov
b1efff46cd Vers cleanups
* Always-false vers_select_conds_t::from_query
* Debug helpers

Closes #684
2018-06-03 23:25:43 +02:00
Sergei Golubchik
486682b1da cleanup: vers tests, remove create_table procedure 2018-06-03 23:25:43 +02:00
Eugene Kosov
aa5683d12e MDEV-15380 Index for versioned table gets corrupt after partitioning and DELETE
In a test case Update occurs between Search and Delete/Update. This corrupts rowid
which Search saves for Delete/Update. Patch prevents this by using of
HA_EXTRA_REMEMBER_POS and HA_EXTRA_RESTORE_POS in a partition code.

This situation possibly occurs only with system versioning table and partition.
MyISAM and Aria engines are affected.

fix by midenok
Closes #705
2018-05-22 13:11:14 +02:00
Aleksey Midenkov
21eccff625 MDEV-15979 DELETE HISTORY from a table with transaction-precise versioning causes Assertion `table_list->vers_conditions.type == SYSTEM_TIME_BEFORE' failure
* Fix versioning.truncate,trx_id to create transaction-based tables
* Fix SYSTEM_TIME_BEFORE condition for VERS_TRX_ID
2018-05-17 15:33:42 +02:00
Alexander Barkov
46be31982a MDEV-16094 Crash when using AS OF with a stored function
MDEV-16100 FOR SYSTEM_TIME erroneously resolves string user variables as transaction IDs

Problem:

Vers_history_point::resolve_unit() tested item->result_type() before
item->fix_fields() was called.

- Item_func_get_user_var::result_type() returned REAL_RESULT by default.
  This caused MDEV-16100.
- Item_func_sp::result_type() crashed on assert.
  This caused MDEV-16094

Changes:
1. Adding item->fix_fields() into Vers_history_point::resolve_unit()
   before using data type specific properties of the history point
   expression.

2. Adding a new virtual method Type_handler::Vers_history_point_resolve_unit()

3. Implementing type-specific
   Type_handler_xxx::Type_handler::Vers_history_point_resolve_unit()
    in the way to:
    a. resolve temporal and general purpose string types to TIMESTAMP
    b. resolve BIT and general purpose INT types to TRANSACTION
    c. disallow use of non-relevant data type expressions in FOR SYSTEM_TIME

    Note, DOUBLE and DECIMAL data types are disallowed intentionally.
    - DOUBLE does not have enough precision to hold huge BIGINT UNSIGNED values
    - DECIMAL rounds on conversion to INT
    Both lack of precision and rounding might potentionally lead to
    very unpredictable results when a wrong transaction ID would be chosen.
    If one really wants dangerous use of DOUBLE and DECIMAL, explicit CAST
    can be used:

      FOR SYSTEM_TIME AS OF CAST(double_or_decimal AS UNSIGNED)

    QQ: perhaps DECIMAL(N,0) could still be allowed.

4. Adding a new virtual method Item::type_handler_for_system_time(),
   to make HEX hybrids and bit literals work as TRANSACTION rather
   than TIMESTAMP.

5. sql_yacc.yy: replacing the rule temporal_literal to "TIMESTAMP TEXT_STRING".
   Other temporal literals now resolve to TIMESTAMP through the new
   Type_handler methods. No special grammar needed. This removed
   a few shift/resolve conflicts.
   (TIMESTAMP related conflicts in "history_point:" will be removed separately)

6. Removing the "timestamp_only" parameter from
   vers_select_conds_t::resolve_units() and Vers_history_point::resolve_unit().
   It was a hint telling that a table did not have any TRANSACTION-aware
   system time columns, so it's OK to resolve to TIMESTAMP in case of uncertainty.
   In the new reduction it works as follows:
   - the decision between TIMESTAMP and TRANSACTION is first made
     based only on the expression data type only
   - then, in case if the expression resolved to TRANSACTION, the table
     is checked if TRANSACTION-aware columns really exist.
   This way is safer against possible ALTER TABLE statements changing
   ROW START and ROW END columns from "BIGINT UNSIGNED" to "TIMESTAMP(x)"
   or the other way around.
2018-05-15 09:33:29 +04:00
Igor Babaev
1b45ede6ab Adjusted test results after mdev-15159. 2018-05-14 19:02:06 -07:00
Eugene Kosov
f08b8fd58d MDEV-15980 FOR SYSTEM_TIME BETWEEN and FROM .. TO work with negative intervals
Fixed by using exactly the same filtering conditions as specified by standard
in 7.6 <table reference> General Rules
2018-05-12 10:16:46 +02:00
Aleksey Midenkov
b1e75d290e MDEV-14823, MDEV-15956 Versioning error messages fixes
MDEV-14823 Wrong error message upon selecting from a system_time partition
MDEV-15956 Strange ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN upon ALTER on versioning column
2018-05-12 10:16:46 +02:00
Aleksey Midenkov
ce2cf855bf MDEV-16043 Assertion thd->Item_change_list::is_empty() failed in mysql_parse upon SELECT from a view reading from a versioned table
Lost restore_active_arena().
Using of Query_arena_stmt is suggested instead.
2018-05-12 10:16:46 +02:00
Sergei Golubchik
8b2fa0ab25 remove obsolete rdiff 2018-05-12 10:16:46 +02:00
Aleksey Midenkov
68cad6aa24 MDEV-16024 transaction_registry.begin_timestamp is wrong for explicit transactions
Store transaction start time in thd->transaction.start_time.
THD::transaction_time() wraps over transaction.start_time taking into
account current status of BEGIN.
2018-05-12 10:16:46 +02:00
Aleksey Midenkov
fd4153f083 MDEV-16010 Too many rows with AS OF point_in_the_past_or_NULL 2018-05-12 10:16:46 +02:00
Aleksey Midenkov
fddaaf7295 MDEV-15978 Add Feature_system_versioning status variable 2018-05-12 10:16:46 +02:00
Eugene Kosov
fe10bf870c MDEV-15893 Rename VTQ to TRT 2018-05-12 10:16:46 +02:00
Sergei Golubchik
a4272bf154 versioning: use @@timestamp
Don't use hidden system time in versioning,
but keep the system time logic in THD
to workaround low-res system clock and
replication not versioned to versioned.

This reverts MDEV-14788 (System versioning cannot
be based on local timestamps, as it is now).
Versioning is based on local timestamps again,
but timestamps are protected by MDEV-15923
(option to control who can set session @@timestamp).
2018-05-12 10:16:46 +02:00
Sergei Golubchik
531acda484 MDEV-14820 System versioning is applied incorrectly to CTEs
Make sure that SELECT_LEX_UNIT::derived, behaves as documented
(points to the "TABLE_LIST representing this union in the
embedding select"). For recursive CTE this was not necessarily
the case, it could've pointed to the TABLE_LIST inside the CTE,
not in the embedding select.

To fix:
* don't update unit->derived in mysql_derived_prepare(), pass derived
  as an argument to st_select_lex_unit::prepare()
* prefer to set unit->derived in TABLE_LIST::init_derived()
  to the TABLE_LIST in the embedding select, not to the recursive
  reference. Fail if there are many TABLE_LISTs in the embedding
  select with conflicting FOR SYSTEM_TIME clauses.

cleanup:
* remove redundant THD* argument from st_select_lex_unit::prepare()
2018-05-12 10:16:45 +02:00
Thirunarayanan Balathandayuthapani
85cc6b70bd MDEV-13134 Introduce ALTER TABLE attributes ALGORITHM=NOCOPY and ALGORITHM=INSTANT
Introduced new alter algorithm type called NOCOPY & INSTANT for
inplace alter operation.

NOCOPY - Algorithm refuses any alter operation that would
rebuild the clustered index. It is a subset of INPLACE algorithm.

INSTANT - Algorithm allow any alter operation that would
modify only meta data. It is a subset of NOCOPY algorithm.

Introduce new variable called alter_algorithm. The values are
DEFAULT(0), COPY(1), INPLACE(2), NOCOPY(3), INSTANT(4)

Message to deprecate old_alter_table variable and make it alias
for alter_algorithm variable.

alter_algorithm variable for slave is always set to default.
2018-05-07 14:58:11 +05:30
Sergei Golubchik
41983fd3b1 MDEV-15788 versioning.partition, versioning.rpl fail on most windows builds in buildbot
fix versioning.partition failures:
* Make the test stable by setting timestamp to fixed values.
2018-04-12 21:20:02 +02:00
Sergei Golubchik
9bd3af97df MDEV-15413 Unexpected errors upon CREATE TABLE .. WITH SYSTEM VERSIONING AS SELECT ...
numerous fixes for CREATE ... SELECT with system versioning:
In CREATE ... SELECT the table is created based on the result set,
field properties do not count. That is
* field invisibility is *not* copied over
* AS ROW START/END is *not* copied over
* the history is *not* copied over
* system row_start/row_end fields can *not* be created from the SELECT part
2018-04-10 13:12:36 +02:00
Aleksey Midenkov
72dd813f7e MDEV-15427 IB: TRX_ID based operations inside transaction generate history
[closes tempesta-tech#472]
2018-04-10 13:12:36 +02:00
Sergei Golubchik
a4251d6f18 MDEV-15391 Server crashes in JOIN::fix_all_splittings_in_plan or Assertion `join->best_read < double(1.79...e+308L)' failed
vers_setup_conds() used to AND all conditions on row_start/row_end
columns and store it either in the WHERE clause or in the ON
clause for some table. In some cases this caused ON clause
to have conditions for tables that aren't part of that ON's join.

Fixed to put a table's condition always in the ON clause of the
corresponding table.

Removed unnecessary ... `OR row_end IS NULL` clause, it's not needed
in the ON clause.

Simplified handling on PS and SP.
2018-04-10 13:12:36 +02:00
Sergei Golubchik
1a86fc5f14 MDEV-15378 Valid query causes invalid view definition due to syntax limitation in FOR SYSTEM_TIME
fix parsing of the AS OF clause
2018-04-10 13:12:36 +02:00
Eugene Kosov
bb56a06d26 MDEV-15062 Information Schema COLUMNS Table does not show system versioning information
get_schema_column_record(): print 'WITHOUT SYSTEM VERSIONING` in 'EXTRA'
for such fields
2018-04-10 13:12:36 +02:00
Sergei Golubchik
041e9de6f8 wording: don't prohibit 2018-04-10 13:12:36 +02:00
Aleksey Midenkov
689f83d0ce MDEV-14790 System versioning for system tables does not work as expected
disallow system versioning for tables in mysql database
2018-04-10 13:12:36 +02:00
Sergei Golubchik
7dcf1b5049 dead code in versioning/common.inc 2018-04-10 13:12:36 +02:00
Sergei Golubchik
35678c9572 dead code - related to vtmd
(will be added back when it'll be used)
2018-04-10 13:12:36 +02:00
Eugene Kosov
19a182b1ea MDEV-15364 FOREIGN CASCADE operations in system versioned referenced tables
Make foreign system versioning tables work in CASCADE UPDATE/SET NULL.
In that case basically row update is performed. This patch makes insert
of a historical row performed too.

row_update_versioned_insert(): restores btr_pcur_t, reads row from it, makes
row historical and inserts to table.

row_ins_check_foreign_constraint(): disable constraint check for historical
rows because it has no sense. Also check will fail always, because referenced
table is updated at that point.

row_update_cascade_for_mysql(): insert historical row for system versioning
tables before updating current row.

revert DATA_VERSIONED -> DATA_UNVERSIONED
2018-03-27 22:35:10 +03:00
Aleksey Midenkov
0cf97ad5b9 IB: CASCADE operation for DELETE
* Removed "Not supported for TIMESTAMP-based" error
* Fixed code duplication with node->vers_set_fields()
* Recovered foreign.test

[closes tempesta-tech#473]
2018-03-19 17:32:46 +03:00
Alexander Barkov
583eb96c24 MDEV-11952 Oracle-style packages: stage#5
- CREATE PACKAGE [BODY] statements are now
  entirely written to mysql.proc with type='PACKAGE' and type='PACKAGE BODY'.
- CREATE PACKAGE BODY now supports IF NOT EXISTS
- DROP PACKAGE BODY now supports IF EXISTS
- CREATE OR REPLACE PACKAGE [BODY] is now supported
- CREATE PACKAGE [BODY] now support the DEFINER clause:

    CREATE DEFINER user@host PACKAGE pkg ... END;
    CREATE DEFINER user@host PACKAGE BODY pkg ... END;

- CREATE PACKAGE [BODY] now supports SQL SECURITY and COMMENT clauses, e.g.:

    CREATE PACKAGE p1 SQL SECURITY INVOKER COMMENT "comment" AS ... END;

- Package routines are now created from the package CREATE PACKAGE BODY
  statement and don't produce individual records in mysql.proc.

- CREATE PACKAGE BODY now supports package-wide variables.
  Package variables can be read and set inside package routines.
  Package variables are stored in a separate sp_rcontext,
  which is cached in THD on the first packate routine call.

- CREATE PACKAGE BODY now supports the initialization section.

- All public routines (i.e. declared in CREATE PACKAGE)
  must have implementations in CREATE PACKAGE BODY

- Only public package routines are available outside of the package

- {CREATE|DROP} PACKAGE [BODY] now respects CREATE ROUTINE and ALTER ROUTINE
  privileges

- "GRANT EXECUTE ON PACKAGE BODY pkg" is now supported

- SHOW CREATE PACKAGE [BODY] is now supported

- SHOW PACKAGE [BODY] STATUS is now supported

- CREATE and DROP for PACKAGE [BODY] now works for non-current databases

- mysqldump now supports packages

- "SHOW {PROCEDURE|FUNCTION) CODE pkg.routine" now works for package routines

- "SHOW PACKAGE BODY CODE pkg" now works (the package initialization section)

- A new package body level MDL was added

- Recursive calls for package procedures are now possible

- Routine forward declarations in CREATE PACKATE BODY are now supported.

- Package body variables now work as SP OUT parameters

- Package body variables now work as SELECT INTO targets

- Package body variables now support ROW, %ROWTYPE, %TYPE
2018-02-25 21:08:19 +04:00
Sergei Golubchik
83ea839fb1 MDEV-15405 Mixed replication fails with "Could not execute Delete_rows_v1 event" upon DELETE HISTORY
Allow slave thread to set time for system versioning

Note that every binlog event stores now(0), while microseconds
are only stored when they're actually used in the query.

Meaning for unversioned->versioned replication, there will be
no microseconds. Need to compensate for that.
2018-02-25 14:31:15 +01:00
Sergei Golubchik
9b59f78d16 MDEV-15395 Wrong result or Assertion `old_part_id == m_last_part' failed in ha_partition::update_row on slave
Revert commit fd240a10e3 and add a test case
2018-02-24 12:29:18 +01:00
Sergei Golubchik
22073cbf3b omit system invisible fields from the duplicate key error
just as SHOW CREATE TABLE omits them from the index definition
2018-02-24 01:28:51 +01:00
Sergei Golubchik
5c7a40e3cf MDEV-15330 Server crash or assertion `table->insert_values' failure in write_record upon LOAD DATA
copy the corresponding line from mysql_prepare_insert()
2018-02-24 01:28:51 +01:00
Sergei Golubchik
fd240a10e3 MDEV-15395 Wrong result or Assertion `old_part_id == m_last_part' failed in ha_partition::update_row on slave
RBR cannot work with system versioning on the master.

row_end column is either system time (not @@timestamp) with microsecond
precision or transaction id. Either way, it'll certainly be different
on the slave. So if the master row contains row_end column, it won't
match on the slave. And if we ignore row_end when comparing,
then some other row might match instead.
2018-02-24 01:28:50 +01:00
Sergei Golubchik
485325e7e3 don't allow TIMESTAMP(6) versioning and FK with CASCADE or SET NULL 2018-02-24 01:28:50 +01:00
Sergei Golubchik
17f8e0ecdf unify error messages a bit 2018-02-24 01:28:45 +01:00
Sergei Golubchik
f3088112cb MDEV-14645: AS OF TIMESTAMP is misused as TRX_ID
Remove 1668efb722 that introduced a special magic
behavior for UNIX_TIMESTAMP() in the AS OF context
2018-02-24 00:50:58 +01:00
Sergei Golubchik
33366b1098 remove @@system_versioning_innodb_algorithm_simple
and delete few garbage-in-garbage-out tests
2018-02-24 00:50:57 +01:00
Aleksey Midenkov
5fb08323e1 Tests: versioning.foreign check row_end after constraint execution 2018-02-24 00:50:57 +01:00
Sergei Golubchik
052668f500 simplify versioning tests 2018-02-24 00:50:57 +01:00
Aleksey Midenkov
dd7d169593 MDEV-14767 system_versioning_alter_history breaks ALTER replication
Vers SQL: force VERS_ALTER_HISTORY_KEEP behavior in the slave thread
2018-02-24 00:50:57 +01:00
Aleksey Midenkov
3f4d03b0dd Tests: partitioning cases for duplicate bugs
MDEV-15191 Assertion `bit < (map)->n_bits' failed in bitmap_is_set
upon INSERT

MDEV-15036 Assertion `!is_set() || (m_status == DA_OK_BULK
&& is_bulk_op())' in Diagnostics_area::set_ok_status or unexpected
ER_RANGE_NOT_INCREASING_ERROR
2018-02-24 00:50:56 +01:00
Eugene Kosov
68c994436a MDEV-15168 Unexpected ER_VERS_ENGINE_UNSUPPORTED upon dropping versioning on a partitioned table
Vers_parse_info::fix_alter_info(): disallow DROP SYSTEM VERSIONING
for system_time partitioned tables.
2018-02-24 00:50:56 +01:00
Sergei Golubchik
f685604aaa MDEV-15103 Assertion in ha_partition::part_records() for updating VIEW
add a test case
2018-02-24 00:50:56 +01:00
Sergei Golubchik
62b5427394 cannot rotate both by INTERVAL and LIMIT 2018-02-24 00:50:56 +01:00