0

Issue

Assuming following 2 views

CREATE VIEW v2 AS SELECT 4711 AS XYZ;
CREATE VIEW v1 AS
  SELECT  
    1                   AS A  
   ,COUNT(DISTINCT (1)) AS B
FROM v2
  GROUP BY A WITH ROLLUP;

Dumping, restoring the dumped file and calling SHOW CREATE VIEW v1; leads to following error:

FAILS with ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'distinct count(distinct 4711)) AS `B` from `dbfail`.`v2` group by `A` with rollu' at line 1

In my understanding the dumpfile looks OK. I assume the import/restore can't handle it.

Of course, above example does not make sence in a business manner. It's reduced to the essence of the problem we are facing!

It works fine

  • in 8.0.18
  • without the ROLLUP modifier
  • or without the DISTINCT count
  • or when v2 is a TABLE
  • OR SURPRISINGLY, and actually the reason for this post ... The failure depends on the names of the views. More precise, their appearance in the dumpfile! If we switch the names of the views v1<->v2 its OK

How to repeat

I'm on macOS Catalina with MySql 8.0.24.

Here's a convenient way of testing the fact in a terminal (on mac). (Feel free to pack it in a script)

The first part is the working one and the second fails due to switched view names.

SCHEMA=dbok
INNERVIEWNAME=v1
OUTERVIEWNAME=v2
mysql -e "DROP DATABASE IF EXISTS $SCHEMA; \
          CREATE DATABASE $SCHEMA; \
          USE $SCHEMA; \
          CREATE VIEW $INNERVIEWNAME AS SELECT 4711 AS anything; \
          CREATE VIEW $OUTERVIEWNAME AS SELECT 4711 AS A, COUNT(DISTINCT(4711)) AS B FROM $INNERVIEWNAME GROUP BY A WITH ROLLUP; \
          SHOW CREATE VIEW $OUTERVIEWNAME;"
rm -rf ./$SCHEMA.mysql
mysqldump $SCHEMA > ./$SCHEMA.mysql
mysql $SCHEMA < ./$SCHEMA.mysql
mysql -e "USE $SCHEMA; SHOW CREATE VIEW $OUTERVIEWNAME;"
SCHEMA=dbfail
INNERVIEWNAME=v2
OUTERVIEWNAME=v1
mysql -e "DROP DATABASE IF EXISTS $SCHEMA; \
          CREATE DATABASE $SCHEMA; \
          USE $SCHEMA; \
          CREATE VIEW $INNERVIEWNAME AS SELECT 4711 AS anything; \
          CREATE VIEW $OUTERVIEWNAME AS SELECT 4711 AS A, COUNT(DISTINCT(4711)) AS B FROM $INNERVIEWNAME GROUP BY A WITH ROLLUP; \
          SHOW CREATE VIEW $OUTERVIEWNAME;"
rm -rf ./$SCHEMA.mysql
mysqldump $SCHEMA > ./$SCHEMA.mysql
mysql $SCHEMA < ./$SCHEMA.mysql
mysql -e "USE $SCHEMA; SHOW CREATE VIEW $OUTERVIEWNAME;"

How can I overcome this problem?

Except for the renaming, of course!. Is anybody else facing this problem too? Is there a proper solution (e.g. dump restore params)? I could not find any comment on this issue yet ...

RST
  • 13
  • 5

2 Answers2

0

In mysql 8.0.23, the mysqldump looks like below, and i cannot see a correct CREATE VIEW statement in it.

Maybe you have found a bug, and should report it to: https://bugs.mysql.com/ ?

EDIT: oops, I always thought that where (a lot of) comments, but: WHOA! These aren't really comments even though they look that way. They are conditional-execution tokens.

-- MySQL dump 10.13  Distrib 8.0.23, for Win64 (x86_64)
--
-- Host: localhost    Database: test
-- ------------------------------------------------------
-- Server version   8.0.23

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Temporary view structure for view `v1`
--

DROP TABLE IF EXISTS `v1`;
/*!50001 DROP VIEW IF EXISTS `v1`*/;
SET @saved_cs_client     = @@character_set_client;
/*!50503 SET character_set_client = utf8mb4 */;
/*!50001 CREATE VIEW `v1` AS SELECT 
 1 AS `A`,
 1 AS `B`*/;
SET character_set_client = @saved_cs_client;

--
-- Final view structure for view `v1`
--

/*!50001 DROP VIEW IF EXISTS `v1`*/;
/*!50001 SET @saved_cs_client          = @@character_set_client */;
/*!50001 SET @saved_cs_results         = @@character_set_results */;
/*!50001 SET @saved_col_connection     = @@collation_connection */;
/*!50001 SET character_set_client      = cp850 */;
/*!50001 SET character_set_results     = cp850 */;
/*!50001 SET collation_connection      = cp850_general_ci */;
/*!50001 CREATE ALGORITHM=UNDEFINED */
/*!50013 DEFINER=`luuk`@`%` SQL SECURITY DEFINER */
/*!50001 VIEW `v1` AS select rollup_group_item(1,0) AS `A`,rollup_sum_switcher(distinct count(distinct 1)) AS `B` from `v2` group by `A` with rollup */;
/*!50001 SET character_set_client      = @saved_cs_client */;
/*!50001 SET character_set_results     = @saved_cs_results */;
/*!50001 SET collation_connection      = @saved_col_connection */;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2021-05-04 19:37:14
Luuk
  • 12,245
  • 5
  • 22
  • 33
0

Issue is fixed in 8.0.26. See MySQL Bug #103583

RST
  • 13
  • 5
  • tested: indeed, above scenario works on a MySQL 8.0.26 installation on macOS Catalina (10.15.7). – RST Aug 09 '21 at 13:37