summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2020-10-01 16:35:55 +0200
committerSergei Golubchik <serg@mariadb.org>2020-10-23 15:53:41 +0200
commit2cd5df8c83d018d1aa58c8426b8406c3c6528d7e (patch)
treee170d8775dae532c77795ca11f8aaa3ae60e13f5
parent15f03c204159325c343bd8c793f71edad0be3347 (diff)
downloadmariadb-git-2cd5df8c83d018d1aa58c8426b8406c3c6528d7e.tar.gz
MDEV-23656 view: removal of parentheses results in wrong result
Item_ref should have the precedence of the item it's referencing
-rw-r--r--mysql-test/r/precedence_bugs.result13
-rw-r--r--mysql-test/t/precedence_bugs.test10
-rw-r--r--sql/item.h6
3 files changed, 28 insertions, 1 deletions
diff --git a/mysql-test/r/precedence_bugs.result b/mysql-test/r/precedence_bugs.result
new file mode 100644
index 00000000000..a9b1cd81503
--- /dev/null
+++ b/mysql-test/r/precedence_bugs.result
@@ -0,0 +1,13 @@
+#
+# MDEV-23656 view: removal of parentheses results in wrong result
+#
+create table t1 (a int, b decimal(10,2));
+insert into t1 values (1, 10.2);
+create view v1 as select avg(b) / (2 + a) from t1;
+show create view v1;
+View v1
+Create View CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select avg(`t1`.`b`) / (2 + `t1`.`a`) AS `avg(b) / (2 + a)` from `t1`
+character_set_client latin1
+collation_connection latin1_swedish_ci
+drop view v1;
+drop table t1;
diff --git a/mysql-test/t/precedence_bugs.test b/mysql-test/t/precedence_bugs.test
new file mode 100644
index 00000000000..6e00fee41a5
--- /dev/null
+++ b/mysql-test/t/precedence_bugs.test
@@ -0,0 +1,10 @@
+
+--echo #
+--echo # MDEV-23656 view: removal of parentheses results in wrong result
+--echo #
+create table t1 (a int, b decimal(10,2));
+insert into t1 values (1, 10.2);
+create view v1 as select avg(b) / (2 + a) from t1;
+query_vertical show create view v1;
+drop view v1;
+drop table t1;
diff --git a/sql/item.h b/sql/item.h
index 4a761bfd70a..6c48d570203 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -4541,7 +4541,11 @@ public:
{
(*ref)->restore_to_before_no_rows_in_result();
}
- virtual void print(String *str, enum_query_type query_type);
+ void print(String *str, enum_query_type query_type);
+ enum precedence precedence() const
+ {
+ return ref ? (*ref)->precedence() : DEFAULT_PRECEDENCE;
+ }
void cleanup();
Item_field *field_for_view_update()
{ return (*ref)->field_for_view_update(); }