[MDEV-15704] Fix Item_param::basic_const_item() to return true for temporal bound values Created: 2018-03-28  Updated: 2020-05-05

Status: Open
Project: MariaDB Server
Component/s: Data types
Affects Version/s: 10.3
Fix Version/s: 10.4

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Unresolved Votes: 0
Labels: None

Epic Link: Data type cleanups

 Description   

There is an asymmetry for temporal data types in Item_param:

bool Item_param::basic_const_item() const
{
  DBUG_ASSERT(fixed || state == NO_VALUE);
  if (state == NO_VALUE ||
      (state == SHORT_DATA_VALUE && type_handler()->cmp_type() == TIME_RESULT))
    return FALSE;
  return TRUE;
}

Notice, unlike for other data types, basic_const_item() returns false for bound temporal values.

The reason for this was probably because prior to 10.0 we didn't have Item_temporal_literal (and its descendants) so that Item_param::clone_item() could not return a basic constant for temporal values.
Now this asymmetry can be fixed, so Item_param::clone_item() returns non-NULL values for all data types.

This asymmetry affects negatively various aspects, for example, constant propagation may not work as efficient, as for other data types.

Also, in this example:

EXECUTE IMMEDIATE 'CREATE OR REPLACE TABLE t1 (a TIME DEFAULT ?)' USING TIME'10:10:10';

the default value is stored in the FRM as an expression rather than a constant (its visible if one opens the frm in a text editor).

For non-temporal data types, Item_param used in DEFAULT clause is converted to constants, e.g.:

EXECUTE IMMEDIATE 'CREATE OR REPLACE TABLE t1 (a INT DEFAULT ?)' USING 10;

In this example, the default integer value 10 is stored in the FRM as an expression rather than a constant.


Generated at Thu Feb 08 08:23:23 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.