Commit graph

80 commits

Author SHA1 Message Date
Monty
dfdedd46e4 MDEV-32188 make TIMESTAMP use whole 32-bit unsigned range
This patch extends the timestamp from
2038-01-19 03:14:07.999999 to 2106-02-07 06:28:15.999999
for 64 bit hardware and OS where 'long' is 64 bits.
This is true for 64 bit Linux but not for Windows.

This is done by treating the 32 bit stored int as unsigned instead of
signed.  This is safe as MariaDB has never accepted dates before the epoch
(1970).
The benefit of this approach that for normal timestamp the storage is
compatible with earlier version.

However for tables using system versioning we before stored a
timestamp with the year 2038 as the 'max timestamp', which is used to
detect current values.  This patch stores the new 2106 year max value
as the max timestamp. This means that old tables using system
versioning needs to be updated with mariadb-upgrade when moving them
to 11.4. That will be done in a separate commit.
2024-05-27 12:39:02 +02:00
Alexander Barkov
351a8eecf0 MDEV-32148 Inefficient WHERE timestamp_column=datetime_const_expr
Changing the way how a the following conditions are evaluated:

    WHERE timestamp_column=datetime_const_expr

(for all comparison operators: =, <=>, <, >, <=, >=, <> and for NULLIF)

Before the change it was always performed as DATETIME.
That was not efficient, as involved per-row TIMESTAMP->DATETIME conversion
for timestamp_column. For example, in case of the SYSTEM time zone
it involved a localtime_r() call, which is known to be slow.

After the change it's performed as TIMESTAMP in many cases.
This allows to avoid per-row conversion, as it works the other way around:
datetime_const_expr is converted to TIMESTAMP once before the execution stage.

Note, datetime_const_expr must be inside monotone continuous periods of
the current time zone, i.e. not near these anomalies:
- DST changes (spring forward, fall back)
- leap seconds
2024-01-12 15:24:05 +04:00
Sergei Golubchik
e95bba9c58 Merge branch '10.5' into 10.6 2023-12-17 11:20:43 +01:00
Sergei Golubchik
98a39b0c91 Merge branch '10.4' into 10.5 2023-12-02 01:02:50 +01:00
Aleksey Midenkov
74883f5e2f MDEV-32082 Server crash in find_field_in_table
Attempt to resolve FOR SYSTEM_TIME expression as field for derived
table is done before derived table is fully prepared, so we fail on
assertion that table_list->table is missing.

Actually Vers_history_point::resolve_unit() is done under the call of
mysql_derived_prepare() itself (sql_derived.cc:824) and the table is
assigned later at 867.

The fix disables unit resolution for field type in FOR SYSTEM_TIME
expression as it does a little sense in any case: making historical
queries based on variable field values produces the result of multiple
time points.

fix_fields_if_needed() in resolve_units() was introduced by 46be31982a
2023-11-10 15:46:15 +03:00
Marko Mäkelä
9608773f75 MDEV-4750 follow-up: Reduce disabling innodb_stats_persistent
This essentially reverts commit 4e89ec6692
and only disables InnoDB persistent statistics for tests where it is
desirable. By design, InnoDB persistent statistics will not be updated
except by ANALYZE TABLE or by STATS_AUTO_RECALC.

The internal transactions that update persistent InnoDB statistics
in background tasks (with innodb_stats_auto_recalc=ON) may cause
nondeterministic query plans or interfere with some tests that deal
with other InnoDB internals, such as the purge of transaction history.
2021-08-31 13:55:02 +03:00
Dmitry Shulga
97e8d27bed MDEV-16708: fix in test failures(added --enable_prepared_warnings/--disable_prepared_warnings) 2021-06-17 19:30:24 +02:00
Marko Mäkelä
1657b7a583 Merge 10.4 to 10.5 2020-10-22 17:08:49 +03:00
Marko Mäkelä
46957a6a77 Merge 10.3 into 10.4 2020-10-22 13:27:18 +03:00
Aleksey Midenkov
a3c379ea61 MDEV-23799 CREATE .. SELECT wrong result on join versioned table
For join to work correctly versioning condition must be added to table
on_expr. Without that JOIN_CACHE gets expression (1)

  trigcond(xtitle.row_end = TIMESTAMP'2038-01-19 06:14:07.999999') and
  trigcond(xtitle.elementId = x.`id` and xtitle.pkey = 'title')

instead of (2)

  trigcond(xtitle.elementId = x.`id` and xtitle.pkey = 'title')

for join_null_complements(). It is NULL-row of xtitle for
complementing the join and the above comparisons of course FALSE, but
trigcond (Item_func_trig_cond) makes them TRUE via its trig_var
property which is bound to some boolean properties of JOIN_TAB.

Expression (2) evaluated to TRUE because its trig_var is bound to
first_inner_tab->not_null_compl. The expression (1) does not evaluate
correctly because row_end comparison's trig_var is bound to
first_inner->found earlier. As a result JOIN_CACHE::check_match()
skipped the row for join_null_complements().

When we add versioning condition to table's on_expr the optimizer in
make_join_select() distributes conditions differently. tmp_cond
inherits on_expr value and in Good case it is full expression

xgender.elementId = x.`id` and xgender.pkey = 'gender' and
xgender.row_end = TIMESTAMP'2038-01-19 06:14:07.999999'

while in Bad case it is only

xgender.elementId = x.`id` and xgender.pkey = 'gender'.

Later in Good row_end condition is optimized out and we get one
trigcond in form of (2).
2020-10-20 10:49:54 +03:00
Marko Mäkelä
4a0b56f604 Merge 10.4 into 10.5 2020-05-31 10:28:59 +03:00
Marko Mäkelä
6da14d7b4a Merge 10.3 into 10.4 2020-05-30 11:04:27 +03:00
Aleksey Midenkov
57f7b4866f MDEV-16937 Strict SQL with system versioned tables causes issues (10.4)
Respect system fields in NO_ZERO_DATE mode.

This is the subject for refactoring in MDEV-19597

Conflict resolution from 7d5223310789f967106d86ce193ef31b315ecff0
2020-05-29 11:45:19 +03:00
Aleksey Midenkov
19da9a51ae MDEV-16937 Strict SQL with system versioned tables causes issues
Respect system fields in NO_ZERO_DATE mode.

This is the subject for refactoring in MDEV-19597
2020-05-28 22:22:20 +03:00
Aleksey Midenkov
dd9773b723 MDEV-22413 Server hangs upon UPDATE on a view reading from versioned partitioned table
UPDATE gets access to history records because versioning conditions
are not set for VIEW. This leads to endless loop of inserting history
records when clustered index is rebuilt and ha_rnd_next() returns
newly inserted history record.

Return back original behavior of failing on write-locked table in
historical query.

35b679b9 assumed that SELECT_LEX::lock_type influences anything, but
actually at this point table is already locked. Original bug report
was tempesta-tech/mariadb#102
2020-05-28 22:22:19 +03:00
Marko Mäkelä
28c89b7151 Merge 10.4 into 10.5 2019-12-16 07:47:17 +02:00
Oleksandr Byelkin
a15234bf4b Merge branch '10.3' into 10.4 2019-12-09 15:09:41 +01:00
Aleksey Midenkov
be92dce613 MDEV-21234 Server crashes in in setup_on_expr upon 3rd execution of SP
Versioned conditions in on_expr can not be rebuilt at optimization
stage on non-conventional arena.
2019-12-05 23:53:07 +03:00
Aleksey Midenkov
8ed646f071 Merge 10.4 into 10.5 2019-12-02 13:35:54 +03:00
Aleksey Midenkov
1d46923a0f MDEV-18929 2nd execution of SP does not detect ER_VERS_NOT_VERSIONED (10.4)
Don't do skip_setup_conds() unless all errors are checked.

Fixes following errors:
      ER_PERIOD_NOT_FOUND
      ER_VERS_QUERY_IN_PARTITION
      ER_VERS_ENGINE_UNSUPPORTED
      ER_VERS_NOT_VERSIONED
2019-12-02 12:46:15 +03:00
Aleksey Midenkov
db32d9457e MDEV-18929 2nd execution of SP does not detect ER_VERS_NOT_VERSIONED
Don't do skip_setup_conds() unless all errors are checked.

Fixes following errors:
      ER_PERIOD_NOT_FOUND
      ER_VERS_QUERY_IN_PARTITION
      ER_VERS_ENGINE_UNSUPPORTED
      ER_VERS_NOT_VERSIONED
2019-12-02 11:48:37 +03:00
Aleksey Midenkov
58fdf5b2fa MDEV-16144 Default TIMESTAMP clause for SELECT from versioned
1. Removed TIMESTAMP/TRANSACTION unit auto-detection in favor of default TIMESTAMP.

Reasons:

1.1. rare practical use and doubtful advantage of such auto-detection;
1.2. it conflicts with MDEV-16226 (TRX_ID-based versioned tables performance improvement).

Needless check_unit membership removed.

2. SQL: versioning type handling refactoring

Vers_type_handler hierarchy stores versioning properties of type.

virtual Type_handler::vers() accesses specialization of
Vers_type_handler for specific type.

virtual Vers_type_handler::kind() returns versioning kind
(timestamp/trx_id).

Removed Type_handler::Vers_history_point_check_unit() in favor of
Type_handler::vers().

Renames:

require_timestamp() -> require_timestamp_error()
require_trx_id() -> require_trx_id_error()

EDIT by Alexander Barkov (@abarkov):

check_sys_fields() moved to Vers_type_handler::check_sys_fields()
2019-09-30 14:05:09 +03:00
Sergei Golubchik
244f0e6dd8 Merge branch '10.3' into 10.4 2019-09-06 11:53:10 +02:00
Monty
a071e0e029 Merge branch '10.2' into 10.3 2019-09-03 13:17:32 +03:00
Nikita Malyavin
47e28a94d5 MDEV-16973 Application-time periods: DELETE
* inject portion of time updates into mysql_delete main loop
* triggered case emits delete+insert, no updates
* PORTION OF `SYSTEM_TIME` is forbidden
* `DELETE HISTORY .. FOR PORTION OF ...` is forbidden as well
2019-02-21 14:48:04 +01:00
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
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
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
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
Eugene Kosov
fe10bf870c MDEV-15893 Rename VTQ to TRT 2018-05-12 10:16:46 +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
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
f1bd02d994 MDEV-15004 parser greedily parses AS OF TIMESTAMP
* TIMESTAMP precedence fixed.
2018-02-23 15:33:23 +01:00
Eugene Kosov
fbed4ca4f1 MDEV-14816 Assertion join->best_read < double(1.797...e+308L) failed in bool greedy_search 2018-01-12 21:20:24 +01:00
Sergei Golubchik
b85efdc3af rename system_time columns
sys_trx_start -> row_start
sys_trx_end -> row_end
2018-01-09 15:49:07 +03:00
Sergei Golubchik
35b679b924 SQL: error messages
remove unused error messages
reword ER_VERS_SYS_FIELD_NOT_HIDDEN->ER_VERS_SYS_FIELD_EXISTS
2018-01-09 14:16:47 +03:00
Sergei Golubchik
e6a7457653 SQL: derived, hiding, error messages
Many related changes.

Note that AS OF condition must always be pushed down to physical tables,
it cannot be applied to a derived or a view. Thus:

* no versioning for internal temporary tables, they can never store
  historical data.
* remove special versioning code from mysql_derived_prepare and
  remove ER_VERS_DERIVED_PROHIBITED - derived can have no historical
  data and cannot be prohibited for system versioning related reasons.
* do not expand select list for derived/views with sys vers fields,
  derived/views can never have historical data.
* remove special invisiblity rules for sys vers fields, they are no
  longer needed after the previous change
* remove system_versioning_hide, it lost the meaning after the
  previous change.
* remove ER_VERS_SYSTEM_TIME_CLASH, it's no "clash", the inner
  AS OF clause always wins.
* non-versioned fields in a historical query

reword the warning text, downgrade to note, don't
replace values with NULLs
2018-01-09 14:12:41 +03:00
Aleksey Midenkov
c5d0c38efc MDEV-14676 Redundancy in error codes
ER_VERS_NOT_VERSIONED vs ER_VERSIONING_REQUIRED
2017-12-19 22:05:25 +03:00
Aleksey Midenkov
ee68d019d1 SQL: removed VERS_HIDDEN_FLAG [closes #409] 2017-12-19 16:12:56 +03:00
Aleksey Midenkov
b55a149194
Timestamp-based versioning for InnoDB [closes #209]
* Removed integer_fields check
* Reworked Vers_parse_info::check_sys_fields()
* Misc renames
* versioned as vers_sys_type_t

* Removed versioned_by_sql(), versioned_by_engine()

versioned() works as before;
versioned(VERS_TIMESTAMP) is versioned_by_sql();
versioned(VERS_TRX_ID) is versioned_by_engine().

* create_tmp_table() fix
* Foreign constraints for timestamp-based
* Range auto-specifier fix
* SQL: 1-row partition rotation fix [fixes #260]
* Fix 'drop system versioning, algorithm=inplace'
2017-12-18 19:03:51 +03:00
Aleksey Midenkov
4624e565f3 System Versioning 1.0 pre6
Merge remote-tracking branch 'mariadb/bb-10.3-temporal-serg' into trunk
2017-12-15 18:12:18 +03:00
Aleksey Midenkov
70d7672377 SQL: MDEV-14633 Assertion on TRT read [fixes #406] 2017-12-15 16:42:25 +03:00
Aleksey Midenkov
2ae2876a6c MDEV-14652 NATURAL JOIN crash in mark_common_columns() [fixes #405]
SQL: reverted NATURAL JOIN fix #161 (deprecated by #383)
2017-12-14 21:31:38 +03:00
Aleksey Midenkov
f96815fe97 SQL: unit resolution Item_field not yet accessible [fixes #398] 2017-12-14 18:42:53 +03:00
Aleksey Midenkov
1668efb722 MDEV-14645: AS OF TIMESTAMP is misused as TRX_ID [fixes #396] 2017-12-14 18:14:21 +03:00
Sergei Golubchik
ca6454bcfe for now, remove FOR SYSTEM_TIME at the end of the query
non-standard, redundant, potentially risky in the future,
hides bugs. See #383, #384, #385

Fixed a parser bug where
SELECT * FROM (t1 join t2) FOR SYSTEM_TIME ...
was not an error.
2017-12-13 21:51:20 +01:00
Aleksey Midenkov
947aa0bab9 SQL: vers_setup_select() misc refactoring
Renamed to SELECT_LEX::vers_setup_conds().
Moved optimized fields check to JOIN::vers_check_items().
2017-12-08 19:37:24 +03:00
Aleksey Midenkov
ad51d77f79 SQL: WHERE top level item [#365 bug 11]
Tests affected (forced mode):

main.range main.range_mrr_icp
2017-12-08 16:26:18 +03:00
Sergei Golubchik
3198bc839d Parser: unreserve keywords
SELECT * FROM t1 FOR SYSTEM_TIME AS OF ...

becomes ambiguous, but it's the same as with

SELECT ... UNION SELECT ... ORDER BY ...
2017-12-05 15:09:09 +03:00