Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-30744

WITH AS clause doesn't work with an outside column

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Not a Bug
    • 10.11.2
    • N/A
    • compat80

    Description

      The following statement works in MySQL 8 but does not work in MariaDB 11 or 10.5:

      CREATE DATABASE IF NOT EXISTS test;
      USE test;
      CREATE TABLE foo (id int, bar_id int);
      CREATE TABLE bar (id int, bar_column varchar(255));
       
      SELECT
          foo.id,
          foo.bar_id,
          (
              WITH cte AS (
                  SELECT bar.bar_column
                  FROM bar
                  WHERE bar.id = foo.bar_id
              )
              SELECT
                  cte.bar_column
              FROM cte
          )
      FROM foo;
      

      Is this intentional?
      Granted, the above SELECT doesn't make much sense but this is a minimal code needed for reproducing this error. I assure you it makes sense in my actual case

      Steps to reproduce:

      1. Create a docker-compose.yml file with the following contents:

      version: '3.5'
       
      services:
          mysql:
              image: mysql:8
              container_name: mysql
              environment:
                  MYSQL_DATABASE: test
                  MYSQL_ROOT_PASSWORD: test
                  MYSQL_PASSWORD: test
          mariadb:
              image: mariadb:10.11
              container_name: mariadb
              environment:
                  MARIADB_ROOT_PASSWORD: test
      

      2. Run `docker-compose up -d` to pull the images and run the containers
      3. Run `docker exec -it mysql mysql -u root -ptest` to enter the MySQL database
      4. Execute the above SQL statements - should result in "Empty set (0.01 sec)".
      5. Exit the MySQL database
      6. Run `docker exec -it mariadb mariadb -u root -ptest` to enter the MariaDB database
      7. Execute SQL statements again and it will result in "ERROR 1054 (42S22): Unknown column 'foo.bar_id' in 'where clause'"

      Optionally:
      8. Change MySQL version in the docker-compose.yml file to 11.0-rc
      9. Run `docker-compose down` to destroy everything
      10. Run `docker-compose up -d` again and repeat steps 6 and 7 - same result.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              kubaszymanowski Jakub Szymanowski
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.