[MDEV-6996] SET STATEMENT default_week_format = .. has no effect Created: 2014-11-01  Updated: 2015-02-02  Resolved: 2014-12-02

Status: Closed
Project: MariaDB Server
Component/s: Admin statements
Affects Version/s: N/A
Fix Version/s: 10.1.2

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Oleksandr Byelkin
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-5231 Per query variables from Percona Serv... Closed
relates to MDEV-6923 Testing for SET STATEMENT .. FOR (MDE... Closed

 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.



 Comments   
Comment by Oleksandr Byelkin [ 2014-11-05 ]

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;

Comment by Oleksandr Byelkin [ 2014-11-05 ]

The variable prohibited as a workaround.

Comment by Oleksandr Byelkin [ 2014-11-11 ]

Parameters set during parsing so changing variables has no effect.

Comment by Sergei Golubchik [ 2014-11-29 ]

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;

Comment by Sergei Golubchik [ 2014-11-29 ]

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

Comment by Oleksandr Byelkin [ 2014-12-01 ]

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

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