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

SET STATEMENT default_week_format = .. has no effect

Details

    Description

      MariaDB [test]> SELECT @@default_week_format;
      +-----------------------+
      | @@default_week_format |
      +-----------------------+
      |                     0 |
      +-----------------------+
      1 row in set (0.00 sec)
       
      MariaDB [test]> SELECT WEEK('2000-01-01');
      +--------------------+
      | WEEK('2000-01-01') |
      +--------------------+
      |                  0 |
      +--------------------+
      1 row in set (0.00 sec)
       
      MariaDB [test]> SELECT WEEK('2000-01-01',2);
      +----------------------+
      | WEEK('2000-01-01',2) |
      +----------------------+
      |                   52 |
      +----------------------+
      1 row in set (0.00 sec)

      MariaDB [test]> SET STATEMENT default_week_format = 2 FOR SELECT WEEK('2000-01-01');
      +--------------------+
      | WEEK('2000-01-01') |
      +--------------------+
      |                  0 |
      +--------------------+
      1 row in set (0.01 sec)
       
      MariaDB [test]> SET default_week_format = 2;
      Query OK, 0 rows affected (0.00 sec)
       
      MariaDB [test]> SELECT WEEK('2000-01-01');
      +--------------------+
      | WEEK('2000-01-01') |
      +--------------------+
      |                 52 |
      +--------------------+
      1 row in set (0.00 sec)

      All the same in Percona server.

      Attachments

        Issue Links

          Activity

            sanja Oleksandr Byelkin added a comment - - edited

            The problem is that week format put as an constant argument during parsing:

                        Item *i1= new (thd->mem_root) Item_int((char*) "0",
                                                       thd->variables.default_week_format,
                                                               1);
                        if (i1 == NULL)
                          MYSQL_YYABORT;
                        $$= new (thd->mem_root) Item_func_week($3, i1);
                        if ($$ == NULL)
                          MYSQL_YYABORT;

            sanja Oleksandr Byelkin added a comment - - edited The problem is that week format put as an constant argument during parsing: Item *i1= new (thd->mem_root) Item_int((char*) "0", thd->variables.default_week_format, 1); if (i1 == NULL) MYSQL_YYABORT; $$= new (thd->mem_root) Item_func_week($3, i1); if ($$ == NULL) MYSQL_YYABORT;

            The variable prohibited as a workaround.

            sanja Oleksandr Byelkin added a comment - The variable prohibited as a workaround.

            Parameters set during parsing so changing variables has no effect.

            sanja Oleksandr Byelkin added a comment - Parameters set during parsing so changing variables has no effect.

            This is a bug, a variable should not be set during parsing.
            So, keep it enabled and fix the following bug instead:

            create table t1 (a date);
            insert t1 values ('2001-01-01');
            prepare x from "select week(a) from t1";
            execute x;
            set default_week_format = 2;
            execute x;
            alter table t1 engine=myisam;
            execute x;

            serg Sergei Golubchik added a comment - This is a bug, a variable should not be set during parsing. So, keep it enabled and fix the following bug instead: create table t1 (a date ); insert t1 values ( '2001-01-01' ); prepare x from "select week(a) from t1" ; execute x; set default_week_format = 2; execute x; alter table t1 engine=myisam; execute x;

            An easy fix would be to generate Item_func_get_system_var for a second argument.

            serg Sergei Golubchik added a comment - An easy fix would be to generate Item_func_get_system_var for a second argument.

            I did a bit different but fix is:
            [Commits] b14de6a: MDEV-6996: SET STATEMENT default_week_format = .. has no effect
            20.11.14 11:32

            sanja Oleksandr Byelkin added a comment - I did a bit different but fix is: [Commits] b14de6a: MDEV-6996 : SET STATEMENT default_week_format = .. has no effect 20.11.14 11:32

            People

              sanja Oleksandr Byelkin
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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