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

Query succeeds despite unresolved reference to column `a`

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Not a Bug
    • 10.5
    • 10.5.28
    • Server
    • None

    Description

      This was observed after fixing MDEV-32411.

      CREATE TABLE t1 ( a int not null ) ;
      INSERT INTO t1 VALUES (EXISTS(SELECT avg(a) OVER (ORDER BY COUNT(DISTINCT a))));
      

      There is a reference to column `a` in the ORDER BY COUNT(DISTINCT a) which cannot be resolved, however the query executes successfully.

      Attachments

        Issue Links

          Activity

            Take-aways from yesterday call: It seems the above behavior was added intentionally, see:

            commit c7320830a62b0ed3245c476f074c534d3cd20027
            Author: Sergei Golubchik <serg@mariadb.org>
            Date:   Tue Sep 24 19:47:45 2019 +0200
             
                outer references in subqueries in INSERT
                
                remove inconsistent limitation
            

            the meaning of

            INSERT INTO t1 VALUES (t1_col);
            

            is "insert a row with default value of t1_col1".

            https://mariadb.com/kb/en/insert/ has this:

            For one-row statements, the SET clause may be more simple, because you don't need to remember the columns order. All values are specified in the form col = expr.

            Values can also be specified in the form of a SQL expression or subquery. However, the subquery cannot access the same table that is named in the INTO clause.

            Does the last paragraph refer to INSERT ... SET syntax or INSERT ... VALUES syntax?
            According to Igor, one cannot refer to inserted-into table from subquery.
            However here 's a counter example from Rex:

            MariaDB [test]> INSERT INTO t1 (t1a) values ( 1 + (select t1a from t2 where  (select  t3a from t3 where t3.t3a > t1.t1a) ) );
            Query OK, 1 row affected (0.007 sec)
            

            psergei Sergei Petrunia added a comment - Take-aways from yesterday call: It seems the above behavior was added intentionally, see: commit c7320830a62b0ed3245c476f074c534d3cd20027 Author: Sergei Golubchik <serg@mariadb.org> Date: Tue Sep 24 19:47:45 2019 +0200   outer references in subqueries in INSERT remove inconsistent limitation the meaning of INSERT INTO t1 VALUES (t1_col); is "insert a row with default value of t1_col1". https://mariadb.com/kb/en/insert/ has this: For one-row statements, the SET clause may be more simple, because you don't need to remember the columns order. All values are specified in the form col = expr. Values can also be specified in the form of a SQL expression or subquery. However, the subquery cannot access the same table that is named in the INTO clause. Does the last paragraph refer to INSERT ... SET syntax or INSERT ... VALUES syntax? According to Igor, one cannot refer to inserted-into table from subquery. However here 's a counter example from Rex: MariaDB [test]> INSERT INTO t1 (t1a) values ( 1 + (select t1a from t2 where (select t3a from t3 where t3.t3a > t1.t1a) ) ); Query OK, 1 row affected (0.007 sec)
            oleg.smirnov Oleg Smirnov added a comment -

            After SQL processor meeting discussion: possibility to reference a column of a table from VALUES of an INSERT is not a bug but a feature. In this case the default value of the column is taken. MySQL supports this too.

            oleg.smirnov Oleg Smirnov added a comment - After SQL processor meeting discussion: possibility to reference a column of a table from VALUES of an INSERT is not a bug but a feature. In this case the default value of the column is taken. MySQL supports this too.

            People

              sanja Oleksandr Byelkin
              oleg.smirnov Oleg Smirnov
              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.