[MDEV-9576] syntax error on view with nullif and count Created: 2016-02-17  Updated: 2016-02-23  Resolved: 2016-02-23

Status: Closed
Project: MariaDB Server
Component/s: Views
Affects Version/s: 10.1.11
Fix Version/s: 10.1.12

Type: Bug Priority: Critical
Reporter: sippanson bernt Assignee: Sergei Golubchik
Resolution: Fixed Votes: 3
Labels: None
Environment:

windows, openbsd



 Description   

A valid SQL query is

select nullif(count(distinct col1),0) from table1 ;

now if I create this as a view with

create view counts4 AS select nullif(count(distinct col1),0) from table1 ;

and try to look at the view I get an error

select * from counts4;
/* SQL Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '<cache>(count(distinct `testdb5`.`table1`.`col1`)),0) AS `nullif(count(distinct ' at line 1 */

this exact same procedure works fine on mariadb 10.0.23
and this bug may have something to do with https://lists.launchpad.net/maria-developers/msg09111.html

I can't test it on 10.1.10 since windows wont allow me to downgrade and I cant uninstall.
This (again) affects all kodi users that can't create db's anymore

to recreate db

CREATE DATABASE IF NOT EXISTS `testdb5` 
USE `testdb5`;
 
CREATE TABLE IF NOT EXISTS `table1` (
  `col1` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Thanks!



 Comments   
Comment by Elena Stepanova [ 2016-02-17 ]

Thanks for the report.

create table table1 (col1 int);
create view counts4 AS select nullif(count(distinct col1),0) from table1 ;
show create view counts4;

The behavior changed with this commit:

commit ce40ccaf24af2fe395f541cb1079256de8727ccd
Author: Alexander Barkov <bar@mariadb.org>
Date:   Thu Jan 28 13:58:39 2016 +0400
 
    MDEV-9181 (NULLIF(count(table.col)), 0) gives wrong result on 10.1.x
    Wrapping args[0] and args[2] into an Item_cache for aggregate functions.

Before the commit, SHOW CREATE VIEW would pass on a non-debug build; but on debug build, we wouldn't even get this far, because CREATE VIEW would cause an assertion failure. The patch made the assertion failure go away, but now SHOW CREATE fails as described.

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