summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorVarun Gupta <varun.gupta@mariadb.com>2021-01-12 14:25:55 +0530
committerVarun Gupta <varun.gupta@mariadb.com>2021-01-12 18:47:39 +0530
commitab271ee7e22ce1250ec36b09123bfb98bc3f8107 (patch)
treedf91f14e267169e4d3b42f5f0d4c452677730d8e /sql
parent3b94309a6cec8d8149c9f312229d18227036e01d (diff)
downloadmariadb-git-ab271ee7e22ce1250ec36b09123bfb98bc3f8107.tar.gz
MDEV-23826: ORDER BY in view definition leads to wrong result with GROUP BY on query using view
Introduced val_time_packed and val_datetime_packed functions for Item_direct_ref to make sure to get the value from the item it is referring to. The issue for incorrect result was that the item was getting its value from the temporary table rather than from the view.
Diffstat (limited to 'sql')
-rw-r--r--sql/item.cc16
-rw-r--r--sql/item.h19
2 files changed, 34 insertions, 1 deletions
diff --git a/sql/item.cc b/sql/item.cc
index a2753caf496..e633964270b 100644
--- a/sql/item.cc
+++ b/sql/item.cc
@@ -8160,6 +8160,22 @@ bool Item_direct_ref::get_date(MYSQL_TIME *ltime,ulonglong fuzzydate)
}
+longlong Item_direct_ref::val_time_packed()
+{
+ longlong tmp = (*ref)->val_time_packed();
+ null_value= (*ref)->null_value;
+ return tmp;
+}
+
+
+longlong Item_direct_ref::val_datetime_packed()
+{
+ longlong tmp = (*ref)->val_datetime_packed();
+ null_value= (*ref)->null_value;
+ return tmp;
+}
+
+
Item_cache_wrapper::~Item_cache_wrapper()
{
DBUG_ASSERT(expr_cache == 0);
diff --git a/sql/item.h b/sql/item.h
index ed20074a8da..823ffd873b6 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -4671,13 +4671,16 @@ public:
return Item_ref::fix_fields(thd, it);
}
void save_val(Field *to);
+ /* Below we should have all val() methods as in Item_ref */
double val_real();
longlong val_int();
- String *val_str(String* tmp);
my_decimal *val_decimal(my_decimal *);
bool val_bool();
+ String *val_str(String* tmp);
bool is_null();
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
+ longlong val_datetime_packed();
+ longlong val_time_packed();
virtual Ref_Type ref_type() { return DIRECT_REF; }
Item *get_copy(THD *thd, MEM_ROOT *mem_root)
{ return get_item_copy<Item_direct_ref>(thd, mem_root, this); }
@@ -4992,6 +4995,20 @@ public:
}
return Item_direct_ref::get_date(ltime, fuzzydate);
}
+ longlong val_time_packed()
+ {
+ if (check_null_ref())
+ return 0;
+ else
+ return Item_direct_ref::val_time_packed();
+ }
+ longlong val_datetime_packed()
+ {
+ if (check_null_ref())
+ return 0;
+ else
+ return Item_direct_ref::val_datetime_packed();
+ }
bool send(Protocol *protocol, String *buffer);
void save_org_in_field(Field *field,
fast_field_copier data __attribute__ ((__unused__)))