Commit fd004404 authored by Sergei Golubchik's avatar Sergei Golubchik

don't convert WEEK(x) to WEEK(x, @@default_week_format)

parent 867809f2
...@@ -874,7 +874,7 @@ explain extended select period_add("9602",-12),period_diff(199505,"9404"),from_d ...@@ -874,7 +874,7 @@ explain extended select period_add("9602",-12),period_diff(199505,"9404"),from_d
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings: Warnings:
Note 1003 select period_add('9602',-12) AS `period_add("9602",-12)`,period_diff(199505,'9404') AS `period_diff(199505,"9404")`,from_days(to_days('960101')) AS `from_days(to_days("960101"))`,dayofmonth('1997-01-02') AS `dayofmonth("1997-01-02")`,month('1997-01-02') AS `month("1997-01-02")`,monthname('1972-03-04') AS `monthname("1972-03-04")`,dayofyear('0000-00-00') AS `dayofyear("0000-00-00")`,hour('1997-03-03 23:03:22') AS `HOUR("1997-03-03 23:03:22")`,minute('23:03:22') AS `MINUTE("23:03:22")`,second(230322) AS `SECOND(230322)`,quarter(980303) AS `QUARTER(980303)`,week('1998-03-03',@@default_week_format) AS `WEEK("1998-03-03")`,yearweek('2000-01-01',1) AS `yearweek("2000-01-01",1)`,week(19950101,1) AS `week(19950101,1)`,year('98-02-03') AS `year("98-02-03")`,(weekday(curdate()) - weekday(now())) AS `weekday(curdate())-weekday(now())`,dayname('1962-03-03') AS `dayname("1962-03-03")`,unix_timestamp() AS `unix_timestamp()`,sec_to_time((time_to_sec('0:30:47') / 6.21)) AS `sec_to_time(time_to_sec("0:30:47")/6.21)`,curtime() AS `curtime()`,utc_time() AS `utc_time()`,curdate() AS `curdate()`,utc_date() AS `utc_date()`,utc_timestamp() AS `utc_timestamp()`,date_format('1997-01-02 03:04:05','%M %W %D %Y %y %m %d %h %i %s %w') AS `date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w")`,from_unixtime(unix_timestamp('1994-03-02 10:11:12')) AS `from_unixtime(unix_timestamp("1994-03-02 10:11:12"))`,('1997-12-31 23:59:59' + interval 1 second) AS `"1997-12-31 23:59:59" + INTERVAL 1 SECOND`,('1998-01-01 00:00:00' - interval 1 second) AS `"1998-01-01 00:00:00" - INTERVAL 1 SECOND`,('1997-12-31' + interval 1 day) AS `INTERVAL 1 DAY + "1997-12-31"`,extract(year from '1999-01-02 10:11:12') AS `extract(YEAR FROM "1999-01-02 10:11:12")`,('1997-12-31 23:59:59' + interval 1 second) AS `date_add("1997-12-31 23:59:59",INTERVAL 1 SECOND)` Note 1003 select period_add('9602',-12) AS `period_add("9602",-12)`,period_diff(199505,'9404') AS `period_diff(199505,"9404")`,from_days(to_days('960101')) AS `from_days(to_days("960101"))`,dayofmonth('1997-01-02') AS `dayofmonth("1997-01-02")`,month('1997-01-02') AS `month("1997-01-02")`,monthname('1972-03-04') AS `monthname("1972-03-04")`,dayofyear('0000-00-00') AS `dayofyear("0000-00-00")`,hour('1997-03-03 23:03:22') AS `HOUR("1997-03-03 23:03:22")`,minute('23:03:22') AS `MINUTE("23:03:22")`,second(230322) AS `SECOND(230322)`,quarter(980303) AS `QUARTER(980303)`,week('1998-03-03') AS `WEEK("1998-03-03")`,yearweek('2000-01-01',1) AS `yearweek("2000-01-01",1)`,week(19950101,1) AS `week(19950101,1)`,year('98-02-03') AS `year("98-02-03")`,(weekday(curdate()) - weekday(now())) AS `weekday(curdate())-weekday(now())`,dayname('1962-03-03') AS `dayname("1962-03-03")`,unix_timestamp() AS `unix_timestamp()`,sec_to_time((time_to_sec('0:30:47') / 6.21)) AS `sec_to_time(time_to_sec("0:30:47")/6.21)`,curtime() AS `curtime()`,utc_time() AS `utc_time()`,curdate() AS `curdate()`,utc_date() AS `utc_date()`,utc_timestamp() AS `utc_timestamp()`,date_format('1997-01-02 03:04:05','%M %W %D %Y %y %m %d %h %i %s %w') AS `date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w")`,from_unixtime(unix_timestamp('1994-03-02 10:11:12')) AS `from_unixtime(unix_timestamp("1994-03-02 10:11:12"))`,('1997-12-31 23:59:59' + interval 1 second) AS `"1997-12-31 23:59:59" + INTERVAL 1 SECOND`,('1998-01-01 00:00:00' - interval 1 second) AS `"1998-01-01 00:00:00" - INTERVAL 1 SECOND`,('1997-12-31' + interval 1 day) AS `INTERVAL 1 DAY + "1997-12-31"`,extract(year from '1999-01-02 10:11:12') AS `extract(YEAR FROM "1999-01-02 10:11:12")`,('1997-12-31 23:59:59' + interval 1 second) AS `date_add("1997-12-31 23:59:59",INTERVAL 1 SECOND)`
SET @TMP='2007-08-01 12:22:49'; SET @TMP='2007-08-01 12:22:49';
CREATE TABLE t1 (d DATETIME); CREATE TABLE t1 (d DATETIME);
INSERT INTO t1 VALUES ('2007-08-01 12:22:59'); INSERT INTO t1 VALUES ('2007-08-01 12:22:59');
......
...@@ -1152,7 +1152,7 @@ explain extended select week(a) from t1; ...@@ -1152,7 +1152,7 @@ explain extended select week(a) from t1;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t1 system NULL NULL NULL NULL 1 100.00 1 SIMPLE t1 system NULL NULL NULL NULL 1 100.00
Warnings: Warnings:
Note 1003 select week('2000-01-01',@@default_week_format) AS `week(a)` from dual Note 1003 select week('2000-01-01') AS `week(a)` from dual
prepare stmt1 from "select week(a) from t1"; prepare stmt1 from "select week(a) from t1";
execute stmt1; execute stmt1;
week(a) week(a)
......
...@@ -57,7 +57,7 @@ create or replace table t1 (a datetime, b datetime as (utc_timestamp()) PERSISTE ...@@ -57,7 +57,7 @@ create or replace table t1 (a datetime, b datetime as (utc_timestamp()) PERSISTE
ERROR HY000: Function or expression 'utc_timestamp()' cannot be used in the GENERATED ALWAYS AS clause of `b` ERROR HY000: Function or expression 'utc_timestamp()' cannot be used in the GENERATED ALWAYS AS clause of `b`
# WEEK() - one argument version # WEEK() - one argument version
create or replace table t1 (a datetime, b datetime as (week(a)) PERSISTENT); create or replace table t1 (a datetime, b datetime as (week(a)) PERSISTENT);
ERROR HY000: Function or expression '@@default_week_format' cannot be used in the GENERATED ALWAYS AS clause of `b` ERROR HY000: Function or expression 'week()' cannot be used in the GENERATED ALWAYS AS clause of `b`
# MATCH() # MATCH()
create or replace table t1 (a varchar(32), b bool as (match a against ('sample text')) PERSISTENT); create or replace table t1 (a varchar(32), b bool as (match a against ('sample text')) PERSISTENT);
ERROR HY000: Function or expression 'match ... against()' cannot be used in the GENERATED ALWAYS AS clause of `b` ERROR HY000: Function or expression 'match ... against()' cannot be used in the GENERATED ALWAYS AS clause of `b`
......
...@@ -1044,13 +1044,15 @@ uint week_mode(uint mode) ...@@ -1044,13 +1044,15 @@ uint week_mode(uint mode)
longlong Item_func_week::val_int() longlong Item_func_week::val_int()
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
uint year; uint year, week_format;
MYSQL_TIME ltime; MYSQL_TIME ltime;
if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE)) if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE | TIME_NO_ZERO_IN_DATE))
return 0; return 0;
return (longlong) calc_week(&ltime, if (arg_count > 1)
week_mode((uint) args[1]->val_int()), week_format= args[1]->val_int();
&year); else
week_format= current_thd->variables.default_week_format;
return (longlong) calc_week(&ltime, week_mode(week_format), &year);
} }
......
...@@ -334,6 +334,7 @@ class Item_func_second :public Item_int_func ...@@ -334,6 +334,7 @@ class Item_func_second :public Item_int_func
class Item_func_week :public Item_int_func class Item_func_week :public Item_int_func
{ {
public: public:
Item_func_week(THD *thd, Item *a): Item_int_func(thd, a) {}
Item_func_week(THD *thd, Item *a, Item *b): Item_int_func(thd, a, b) {} Item_func_week(THD *thd, Item *a, Item *b): Item_int_func(thd, a, b) {}
longlong val_int(); longlong val_int();
const char *func_name() const { return "week"; } const char *func_name() const { return "week"; }
...@@ -343,6 +344,16 @@ class Item_func_week :public Item_int_func ...@@ -343,6 +344,16 @@ class Item_func_week :public Item_int_func
max_length=2*MY_CHARSET_BIN_MB_MAXLEN; max_length=2*MY_CHARSET_BIN_MB_MAXLEN;
maybe_null=1; maybe_null=1;
} }
bool check_vcol_func_processor(void *arg)
{
if (arg_count == 2)
return FALSE;
return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC);
}
bool check_valid_arguments_processor(void *int_arg)
{
return arg_count == 2;
}
Item *get_copy(THD *thd, MEM_ROOT *mem_root) Item *get_copy(THD *thd, MEM_ROOT *mem_root)
{ return get_item_copy<Item_func_week>(thd, mem_root, this); } { return get_item_copy<Item_func_week>(thd, mem_root, this); }
}; };
...@@ -981,7 +992,12 @@ class Item_extract :public Item_int_func ...@@ -981,7 +992,12 @@ class Item_extract :public Item_int_func
bool eq(const Item *item, bool binary_cmp) const; bool eq(const Item *item, bool binary_cmp) const;
void print(String *str, enum_query_type query_type); void print(String *str, enum_query_type query_type);
bool check_partition_func_processor(void *int_arg) {return FALSE;} bool check_partition_func_processor(void *int_arg) {return FALSE;}
bool check_vcol_func_processor(void *arg) { return FALSE;} bool check_vcol_func_processor(void *arg)
{
if (int_type != INTERVAL_WEEK)
return FALSE;
return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC);
}
bool check_valid_arguments_processor(void *int_arg) bool check_valid_arguments_processor(void *int_arg)
{ {
switch (int_type) { switch (int_type) {
......
...@@ -10022,15 +10022,7 @@ function_call_conflict: ...@@ -10022,15 +10022,7 @@ function_call_conflict:
} }
| WEEK_SYM '(' expr ')' | WEEK_SYM '(' expr ')'
{ {
Item *i1; $$= new (thd->mem_root) Item_func_week(thd, $3);
LEX_STRING name= {C_STRING_WITH_LEN("default_week_format")};
if (!(i1= get_system_var(thd, OPT_SESSION,
name, null_lex_str)))
MYSQL_YYABORT;
i1->set_name(thd, (const char *)
STRING_WITH_LEN("@@default_week_format"),
system_charset_info);
$$= new (thd->mem_root) Item_func_week(thd, $3, i1);
if ($$ == NULL) if ($$ == NULL)
MYSQL_YYABORT; MYSQL_YYABORT;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment