[MDEV-9637] select nullif(count(col1),0) gives wrong result if in a view Created: 2016-02-25  Updated: 2016-03-07  Resolved: 2016-03-07

Status: Closed
Project: MariaDB Server
Component/s: Optimizer, Views
Affects Version/s: 10.1.12
Fix Version/s: 10.1.13

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

openbsd, windows



 Description   

This is related to MDEV-9181 and MDEV-9576.

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

returns 3

creating a view with the same query and it returns 5.
to recreate ->

 
CREATE DATABASE IF NOT EXISTS `testdb5` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `testdb5`;
 
CREATE TABLE IF NOT EXISTS `table1` (
  `col1` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
 
/*!40000 ALTER TABLE `table1` DISABLE KEYS */;
INSERT INTO `table1` (`col1`) VALUES
	('hello'),
	('hello'),
	('hello');
/*!40000 ALTER TABLE `table1` ENABLE KEYS */;
 
 
CREATE TABLE `testview` (
	`nullif(count(col1),0)` BIGINT(21) NULL
) ENGINE=MyISAM;
 
DROP TABLE IF EXISTS `testview`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` VIEW `testview` AS select nullif(count(col1),0) from table1 ;

then

select * from testview


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