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

Strange error message if you try to FLUSH TABLES <view> after LOCK TABLES <view>

Details

    Description

      If you try to execute FLUSH TABLES on a view after read-locking that view with LOCK TABLES ... READ|WRITE, then you get an error message that doesn't seem to make a lot of sense.

      For example, if we have this view:

      CREATE TABLE t (qty INT, price INT);
      CREATE VIEW v AS SELECT qty, price, qty*price AS value FROM t;
      

      Then let's see what happens:

      MariaDB [db1]> LOCK TABLES v READ;
      Query OK, 0 rows affected (0.00 sec)
       
      MariaDB [db1]> FLUSH TABLES v;
      ERROR 1100 (HY000): Table 'v' was not locked with LOCK TABLES
      

      If we execute the same statement on the base table, then we get a different error message:

      MariaDB [db1]> LOCK TABLES t READ;
      Query OK, 0 rows affected (0.00 sec)
       
      MariaDB [db1]> FLUSH TABLES t;
      ERROR 1099 (HY000): Table 't' was locked with a READ lock and can't be updated
      

      Trying to flush a write-locked view has the same problem:

      MariaDB [db1]> LOCK TABLES v WRITE;
      Query OK, 0 rows affected (0.00 sec)
       
      MariaDB [db1]> FLUSH TABLES v;
      ERROR 1100 (HY000): Table 'v' was not locked with LOCK TABLES
      

      But this does work for base tables:

      MariaDB [db1]> LOCK TABLES t WRITE;
      Query OK, 0 rows affected (0.00 sec)
       
      MariaDB [db1]> FLUSH TABLES t;
      Query OK, 0 rows affected (0.00 sec)
      

      Is the error message wrong, or is FLUSH partially broken for views at the moment?

      Attachments

        Issue Links

          Activity

            GeoffMontee Geoff Montee (Inactive) created issue -
            GeoffMontee Geoff Montee (Inactive) made changes -
            Field Original Value New Value
            Summary Wrong error message if you try to FLUSH TABLES <view> after LOCK TABLES <view> READ Strange error message if you try to FLUSH TABLES <view> after LOCK TABLES <view>
            GeoffMontee Geoff Montee (Inactive) made changes -
            Description If you try to execute FLUSH TABLES on a view after read-locking that view with LOCK TABLES ... READ, then you get an error message that doesn't seem to make a lot of sense.

            For example, if we have this view:

            {noformat}
            CREATE TABLE t (qty INT, price INT);
            CREATE VIEW v AS SELECT qty, price, qty*price AS value FROM t;
            {noformat}

            Then let's see what happens:

            {noformat}
            MariaDB [db1]> LOCK TABLES v READ;
            Query OK, 0 rows affected (0.00 sec)

            MariaDB [db1]> FLUSH TABLES v;
            ERROR 1100 (HY000): Table 'v' was not locked with LOCK TABLES
            {noformat}

            If we execute the same statement on the base table, then we get a different error message:

            {noformat}
            MariaDB [db1]> LOCK TABLES t READ;
            Query OK, 0 rows affected (0.00 sec)

            MariaDB [db1]> FLUSH TABLES t;
            ERROR 1099 (HY000): Table 't' was locked with a READ lock and can't be updated
            {noformat}
            If you try to execute FLUSH TABLES on a view after read-locking that view with LOCK TABLES ... READ|WRITE, then you get an error message that doesn't seem to make a lot of sense.

            For example, if we have this view:

            {noformat}
            CREATE TABLE t (qty INT, price INT);
            CREATE VIEW v AS SELECT qty, price, qty*price AS value FROM t;
            {noformat}

            Then let's see what happens:

            {noformat}
            MariaDB [db1]> LOCK TABLES v READ;
            Query OK, 0 rows affected (0.00 sec)

            MariaDB [db1]> FLUSH TABLES v;
            ERROR 1100 (HY000): Table 'v' was not locked with LOCK TABLES
            {noformat}

            If we execute the same statement on the base table, then we get a different error message:

            {noformat}
            MariaDB [db1]> LOCK TABLES t READ;
            Query OK, 0 rows affected (0.00 sec)

            MariaDB [db1]> FLUSH TABLES t;
            ERROR 1099 (HY000): Table 't' was locked with a READ lock and can't be updated
            {noformat}

            Trying to flush a write-locked view has the same problem:

            {noformat}
            MariaDB [db1]> LOCK TABLES v WRITE;
            Query OK, 0 rows affected (0.00 sec)

            MariaDB [db1]> FLUSH TABLES v;
            ERROR 1100 (HY000): Table 'v' was not locked with LOCK TABLES
            {noformat}

            But this does work for base tables:

            {noformat}
            MariaDB [db1]> LOCK TABLES t WRITE;
            Query OK, 0 rows affected (0.00 sec)

            MariaDB [db1]> FLUSH TABLES t;
            Query OK, 0 rows affected (0.00 sec)
            {noformat}

            Is the error message wrong, or is FLUSH partially broken for views at the moment?
            elenst Elena Stepanova made changes -
            Component/s Locking [ 10900 ]
            Fix Version/s 10.2 [ 14601 ]
            Assignee Sergey Vojtovich [ svoj ]
            serg Sergei Golubchik made changes -
            Affects Version/s 10.2 [ 14601 ]
            Affects Version/s 10.3 [ 22126 ]
            Affects Version/s 5.5 [ 15800 ]
            Affects Version/s 10.0 [ 16000 ]
            Affects Version/s 10.1 [ 16100 ]
            Affects Version/s 10.2.14 [ 22911 ]

            I don't see a bug here.

            • FLUSH TABLE requires write lock since 5.5. This is intentional.
            • The error message is not wrong, table 'v' was not locked with LOCK TABLES, indeed. Even view wasn't, LOCK TABLES v locks the underlying table t.
            serg Sergei Golubchik added a comment - I don't see a bug here. FLUSH TABLE requires write lock since 5.5. This is intentional. The error message is not wrong, table 'v' was not locked with LOCK TABLES, indeed. Even view wasn't, LOCK TABLES v locks the underlying table t.
            serg Sergei Golubchik made changes -
            Fix Version/s N/A [ 14700 ]
            Fix Version/s 10.2 [ 14601 ]
            Assignee Sergey Vojtovich [ svoj ] Sergei Golubchik [ serg ]
            Resolution Not a Bug [ 6 ]
            Status Open [ 1 ] Closed [ 6 ]
            elenst Elena Stepanova added a comment - - edited

            For the record, I agree with GeoffMontee that the error message is wrong in the sense that it's confusing and normal-user-unfriendly, even if it's factually correct. For example, ER_IT_IS_A_VIEW would make much more sense, and probably we have more of the kind.

            Also, FWIW, while a table v of course wasn't locked here, the view v actually was:

            MariaDB [test]> lock tables v read;
            Query OK, 0 rows affected (0.00 sec)
             
            MariaDB [test]> select * from information_schema.metadata_lock_info;
            +-----------+----------------------+---------------+---------------------+--------------+------------+
            | THREAD_ID | LOCK_MODE            | LOCK_DURATION | LOCK_TYPE           | TABLE_SCHEMA | TABLE_NAME |
            +-----------+----------------------+---------------+---------------------+--------------+------------+
            |         9 | MDL_SHARED_READ      | NULL          | Table metadata lock | test         | v          |
            |         9 | MDL_SHARED_READ_ONLY | NULL          | Table metadata lock | test         | t          |
            +-----------+----------------------+---------------+---------------------+--------------+------------+
            2 rows in set (0.00 sec)
            

            elenst Elena Stepanova added a comment - - edited For the record, I agree with GeoffMontee that the error message is wrong in the sense that it's confusing and normal-user-unfriendly, even if it's factually correct. For example, ER_IT_IS_A_VIEW would make much more sense, and probably we have more of the kind. Also, FWIW, while a table v of course wasn't locked here, the view v actually was: MariaDB [test]> lock tables v read ; Query OK, 0 rows affected (0.00 sec)   MariaDB [test]> select * from information_schema.metadata_lock_info; + -----------+----------------------+---------------+---------------------+--------------+------------+ | THREAD_ID | LOCK_MODE | LOCK_DURATION | LOCK_TYPE | TABLE_SCHEMA | TABLE_NAME | + -----------+----------------------+---------------+---------------------+--------------+------------+ | 9 | MDL_SHARED_READ | NULL | Table metadata lock | test | v | | 9 | MDL_SHARED_READ_ONLY | NULL | Table metadata lock | test | t | + -----------+----------------------+---------------+---------------------+--------------+------------+ 2 rows in set (0.00 sec)

            LOCK TABLE puts read/write table locks, not only metadata locks. See SHOW OPEN TABLES. And there is no way to put a table lock on a view.

            serg Sergei Golubchik added a comment - LOCK TABLE puts read/write table locks, not only metadata locks. See SHOW OPEN TABLES . And there is no way to put a table lock on a view.

            On the other hand, if LOCK TABLES locks view's tables, perhaps FLUSH TABLES should check whether view's tables were locked, not whether the view itself was locked?

            After all FLUSH TABLES also flushes tables and not the view itself.

            Let's see if it's possible to get rid of this “strange” error message completely by allowing FLUSH TABLES v to work under LOCK TABLES v.

            serg Sergei Golubchik added a comment - On the other hand, if LOCK TABLES locks view's tables, perhaps FLUSH TABLES should check whether view's tables were locked, not whether the view itself was locked? After all FLUSH TABLES also flushes tables and not the view itself. Let's see if it's possible to get rid of this “strange” error message completely by allowing FLUSH TABLES v to work under LOCK TABLES v .
            serg Sergei Golubchik made changes -
            Assignee Sergei Golubchik [ serg ] Alexey Botchkov [ holyfoot ]
            Resolution Not a Bug [ 6 ]
            Status Closed [ 6 ] Stalled [ 10000 ]
            serg Sergei Golubchik made changes -
            Fix Version/s 10.2 [ 14601 ]
            Fix Version/s 10.3 [ 22126 ]
            Fix Version/s 10.1 [ 16100 ]
            Fix Version/s N/A [ 14700 ]
            holyfoot Alexey Botchkov made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]
            holyfoot Alexey Botchkov added a comment - http://lists.askmonty.org/pipermail/commits/2018-June/012606.html
            holyfoot Alexey Botchkov made changes -
            Assignee Alexey Botchkov [ holyfoot ] Sergei Golubchik [ serg ]
            Status In Progress [ 3 ] In Review [ 10002 ]
            serg Sergei Golubchik made changes -
            Assignee Sergei Golubchik [ serg ] Alexey Botchkov [ holyfoot ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            julien.fritsch Julien Fritsch made changes -
            Comment [ A comment with security level 'Developers' was removed. ]

            From Sergei's review:
            ------------------------------------------------------
            That's a pretty neat solution

            But it seems that - contrary to what I expected - that MariaDB actually
            distinguishes between locking a view a locking all its tables. Consider
            this test case:


            create table t1 (a int);
            create view v1 as select * from t1;
            lock table v1 write;
            insert v1 values (1);
            select * from t1;
            unlock tables;
            drop view v1;
            drop table t1;


            this works and inserts 1 just fine. If you change the lock table
            statement to lock t1, it'll with

            Table 'v1' was not locked with LOCK TABLES

            It'd be great if FLUSH TABLES will exhibit the same behavior, it needs
            to know if the view is locked, not only if all underlying tables are
            locked.
            ----------------------------------------------------

            holyfoot Alexey Botchkov added a comment - From Sergei's review: ------------------------------------------------------ That's a pretty neat solution But it seems that - contrary to what I expected - that MariaDB actually distinguishes between locking a view a locking all its tables. Consider this test case: create table t1 (a int); create view v1 as select * from t1; lock table v1 write; insert v1 values (1); select * from t1; unlock tables; drop view v1; drop table t1; this works and inserts 1 just fine. If you change the lock table statement to lock t1, it'll with Table 'v1' was not locked with LOCK TABLES It'd be great if FLUSH TABLES will exhibit the same behavior, it needs to know if the view is locked, not only if all underlying tables are locked. ----------------------------------------------------
            holyfoot Alexey Botchkov made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]
            holyfoot Alexey Botchkov added a comment - Fix proposal v2 http://lists.askmonty.org/pipermail/commits/2018-June/012645.html
            holyfoot Alexey Botchkov made changes -
            Assignee Alexey Botchkov [ holyfoot ] Sergei Golubchik [ serg ]
            Status In Progress [ 3 ] In Review [ 10002 ]
            serg Sergei Golubchik made changes -
            Assignee Sergei Golubchik [ serg ] Alexey Botchkov [ holyfoot ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            holyfoot Alexey Botchkov made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]
            holyfoot Alexey Botchkov added a comment - http://lists.askmonty.org/pipermail/commits/2018-September/012870.html
            holyfoot Alexey Botchkov made changes -
            Fix Version/s 10.1.36 [ 23117 ]
            Fix Version/s 10.2 [ 14601 ]
            Fix Version/s 10.1 [ 16100 ]
            Fix Version/s 10.3 [ 22126 ]
            Resolution Fixed [ 1 ]
            Status In Progress [ 3 ] Closed [ 6 ]
            holyfoot Alexey Botchkov made changes -
            Resolution Fixed [ 1 ]
            Status Closed [ 6 ] Stalled [ 10000 ]
            holyfoot Alexey Botchkov added a comment - http://lists.askmonty.org/pipermail/commits/2018-September/012873.html
            holyfoot Alexey Botchkov made changes -
            Assignee Alexey Botchkov [ holyfoot ] Sergei Golubchik [ serg ]
            Status Stalled [ 10000 ] In Review [ 10002 ]
            serg Sergei Golubchik made changes -
            Assignee Sergei Golubchik [ serg ] Alexey Botchkov [ holyfoot ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            serg Sergei Golubchik made changes -
            Fix Version/s 10.1 [ 16100 ]
            Fix Version/s 10.1.36 [ 23117 ]
            holyfoot Alexey Botchkov added a comment - http://lists.askmonty.org/pipermail/commits/2018-September/012905.html
            holyfoot Alexey Botchkov made changes -
            Assignee Alexey Botchkov [ holyfoot ] Sergei Golubchik [ serg ]
            Status Stalled [ 10000 ] In Review [ 10002 ]
            ratzpo Rasmus Johansson (Inactive) made changes -
            julien.fritsch Julien Fritsch made changes -
            Priority Major [ 3 ] Critical [ 2 ]

            ok to push

            serg Sergei Golubchik added a comment - ok to push
            serg Sergei Golubchik made changes -
            Assignee Sergei Golubchik [ serg ] Alexey Botchkov [ holyfoot ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            serg Sergei Golubchik made changes -
            Fix Version/s 10.2 [ 14601 ]
            serg Sergei Golubchik made changes -
            Fix Version/s 10.3 [ 22126 ]
            holyfoot Alexey Botchkov made changes -
            Fix Version/s 10.1.38 [ 23209 ]
            Fix Version/s 10.2 [ 14601 ]
            Fix Version/s 10.1 [ 16100 ]
            Fix Version/s 10.3 [ 22126 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            holyfoot Alexey Botchkov made changes -
            Fix Version/s 10.3.11 [ 23141 ]
            Fix Version/s 10.2.19 [ 23207 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 86584 ] MariaDB v4 [ 154167 ]
            mariadb-jira-automation Jira Automation (IT) made changes -
            Zendesk Related Tickets 163917

            People

              holyfoot Alexey Botchkov
              GeoffMontee Geoff Montee (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 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.