Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-41575

Partitioning by COLUMNS or KEY on a time zone dependent virtual column changes the query result

    XMLWordPrintable

Details

    Description

      --source include/have_partition.inc
       
      SET time_zone='+00:00';
      # PARTITION BY HASH (v) refuses this column. LIST COLUMNS (v) must refuse it too, or keep the rows where they can be found
      --error 0,ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR
      CREATE TABLE t1 (ts TIMESTAMP, v INT AS (HOUR(ts)) VIRTUAL) PARTITION BY LIST COLUMNS (v) (PARTITION p0 VALUES IN (1), PARTITION p1 DEFAULT);
      if (!$mysql_errno)
      {
        INSERT INTO t1 (ts) VALUES ('2000-01-01 01:00:00');
        SET time_zone='+01:00';
        --let $c= query_get_value(SELECT COUNT(*) AS c FROM t1 WHERE v=2, c, 1)
        if ($c != 1)
        {
          --die The row with v=2 is not found by v=2 after a time_zone change. The time zone dependent v was accepted
        }
        DROP TABLE t1;
      }

      Leads to:

      CS 13.1.0 da18481158c81ca94689702073c3e04aad85a6a3 (Debug, Clang 22.1.8-20260622) Build 18/08/2026

      mysqltest: At line 14: The row with v=2 is not found by v=2 after a time_zone change. The time zone dependent v was accepted

      Partitioning changes the query result. Without partitioning, v=2 finds the row after the same time_zone change. PARTITION BY HASH (v) on the same column gives ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR. PARTITION BY KEY (v) is accepted and misses the row in the same way. InnoDB and optimized builds give the same result.

      From the code it seems that the check for a time zone dependent virtual column runs only for a partitioning expression. fix_fields_part_func() in sql/sql_partition.cc walks the expression with check_valid_arguments_processor, and Item_field::check_valid_arguments_processor() in sql/item.cc checks the expression of a virtual column. For KEY and COLUMNS partitioning, handle_list_of_fields() is called instead, and it does not run this check.

      Attachments

        Issue Links

          Activity

            People

              ycp Yuchen Pei
              Roel Roel Van de Paar
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - Not Specified
                  Not Specified
                  Logged:
                  Time Spent - 1h 10m
                  1h 10m

                  Git Integration

                    Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.