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

Add thread ID and database / table, where the error occured to SQL error plugin

Details

    Description

      For debug purposes, it will useful, if threadID and database/ table name (if available) will be added to the SQL ERROR Plugin log entries.

      Error messages should also be extended so that the database and table name is present for errors related to tables.

      To enable this feature, on has to also do
      sql_error_log_with_db_and_thread_info=1
      See https://mariadb.com/kb/en/sql-error-log-system-variables-and-options/#sql_error_log_with_db_and_thread_info

      Attachments

        Issue Links

          Activity

            thread id — yes, this is very easy to add.
            Database and table name — not possible, there's no way even to define it. table name and db name should be part of the error message, where applicable.

            serg Sergei Golubchik added a comment - thread id — yes, this is very easy to add. Database and table name — not possible, there's no way even to define it. table name and db name should be part of the error message, where applicable.
            ralf.gebhardt Ralf Gebhardt added a comment -

            serg, the audit plugin provides a table event (read/write) with a query id, and a query event with the same query id and an error code. So that could not be used here?

            ralf.gebhardt Ralf Gebhardt added a comment - serg , the audit plugin provides a table event (read/write) with a query id, and a query event with the same query id and an error code. So that could not be used here?

            example:

            MariaDB> update t1, t2 SET a=..., b=... WHERE c=...
            ERROR 23000: Duplicate entry 'ttt' for key 'PRIMARY'
            

            and indeed, you can guess from the last table write event what table was it for. But, really, the error message should mention the table name, it's very confusing for the end user now.

            MariaDB> update t1, t2 SET a=..., b=... WHERE c=...
            ERROR 22003: BIGINT UNSIGNED value is out of range in 'cast(1 as unsigned) - 2'
            

            this may not even have a table name, it might apply to an expression in SET or WHERE, not to a specific table. This error message doesn't have a table name, and that's correct.

            serg Sergei Golubchik added a comment - example: MariaDB> update t1, t2 SET a=..., b=... WHERE c=... ERROR 23000: Duplicate entry 'ttt' for key 'PRIMARY' and indeed, you can guess from the last table write event what table was it for. But, really, the error message should mention the table name, it's very confusing for the end user now. MariaDB> update t1, t2 SET a=..., b=... WHERE c=... ERROR 22003: BIGINT UNSIGNED value is out of range in 'cast(1 as unsigned) - 2' this may not even have a table name, it might apply to an expression in SET or WHERE, not to a specific table. This error message doesn't have a table name, and that's correct.
            ralf.gebhardt Ralf Gebhardt added a comment -

            serg, so you are saying that we should change the error messages themselves where a database and table name where appropriate instead? Only the table name is not enough

            ralf.gebhardt Ralf Gebhardt added a comment - serg , so you are saying that we should change the error messages themselves where a database and table name where appropriate instead? Only the table name is not enough

            Yes, we should, where it's not obvious from the context. "Duplicate entry" error can happen in a multi-table UPDATE, so it should include a table name.

            serg Sergei Golubchik added a comment - Yes, we should, where it's not obvious from the context. "Duplicate entry" error can happen in a multi-table UPDATE, so it should include a table name.
            ralf.gebhardt Ralf Gebhardt added a comment -

            monty, one question as you added an estimate. I this 1 day to add the thread id to the SQL ERROR Plugin log entries or to change all error messages to include database/table names?

            ralf.gebhardt Ralf Gebhardt added a comment - monty , one question as you added an estimate. I this 1 day to add the thread id to the SQL ERROR Plugin log entries or to change all error messages to include database/table names?
            serg Sergei Golubchik added a comment - - edited

            so, we'll add a thread id and in the error message "Can't write; duplicate key in table 'tab1'." (from the original customer's request) we'll add a db name. Neither of this has to be 11.4+, can be done in earlier versions too

            serg Sergei Golubchik added a comment - - edited so, we'll add a thread id and in the error message "Can't write; duplicate key in table 'tab1'." (from the original customer's request) we'll add a db name. Neither of this has to be 11.4+, can be done in earlier versions too
            rucha174 Rucha Deodhar added a comment - - edited

            Patch: https://github.com/MariaDB/server/commit/7dc25883ae368b9ac923a09e3f9a870feaf7ba30

            Error message change as mentioned in the comment (with table name) is already present in 10.6:

            ER_DUP_KEY 23000
                  eng "Can't write; duplicate key in table '%-.192s'"
            

            rucha174 Rucha Deodhar added a comment - - edited Patch: https://github.com/MariaDB/server/commit/7dc25883ae368b9ac923a09e3f9a870feaf7ba30 Error message change as mentioned in the comment (with table name) is already present in 10.6: ER_DUP_KEY 23000 eng "Can't write; duplicate key in table '%-.192s'"

            OK to push (for testing probably)

            sanja Oleksandr Byelkin added a comment - OK to push (for testing probably)

            About the error message. We should also write the name of the key in the error message!

            monty Michael Widenius added a comment - About the error message. We should also write the name of the key in the error message!
            rucha174 Rucha Deodhar added a comment -

            So after talking to serg found out that in very old MySQL there was ER_DUP_KEY error and then we added ER_DUP_KEYNAME because it is more user friendly error message.
            So now ER_DUP_KEY message is only used where ever key name is not available. Also, in some places in the code, we still have ER_DUP_KEY but it is not really triggered because server does not let it get triggered (maybe dead code, not sure). So basically, where ever we can have keyname in error, we have it already. In rest of the places we dont.

            rucha174 Rucha Deodhar added a comment - So after talking to serg found out that in very old MySQL there was ER_DUP_KEY error and then we added ER_DUP_KEYNAME because it is more user friendly error message. So now ER_DUP_KEY message is only used where ever key name is not available. Also, in some places in the code, we still have ER_DUP_KEY but it is not really triggered because server does not let it get triggered (maybe dead code, not sure). So basically, where ever we can have keyname in error, we have it already. In rest of the places we dont.

            ok to push

            ramesh Ramesh Sivaraman added a comment - ok to push
            rucha174 Rucha Deodhar added a comment -

            pushed to 10.6

            rucha174 Rucha Deodhar added a comment - pushed to 10.6
            rucha174 Rucha Deodhar added a comment - - edited

            A new global variable with_db_and_thread_info for the error logging plugin is added. If set to 1(enabled), it prints the database name and the thread ID in the log in addition to already existing columns. Default value is 0. It cannot be set at runtime to keep the entire log with same formatting.

            Example when select is done from a non existing table with enabled with_db_and_thread_info, the log will have:

            2023-10-31 15:54:37 4 root[root] @ localhost [] `test` ERROR 1146: Table 'test.t_doesnt_exist' doesn't exist : select * from t_doesnt_exist

            If no database is selected, then there is NULL in place of database instead of being empty.

            rucha174 Rucha Deodhar added a comment - - edited A new global variable with_db_and_thread_info for the error logging plugin is added. If set to 1(enabled), it prints the database name and the thread ID in the log in addition to already existing columns. Default value is 0. It cannot be set at runtime to keep the entire log with same formatting. Example when select is done from a non existing table with enabled with_db_and_thread_info, the log will have: 2023-10-31 15:54:37 4 root [root] @ localhost [] `test` ERROR 1146: Table 'test.t_doesnt_exist' doesn't exist : select * from t_doesnt_exist If no database is selected, then there is NULL in place of database instead of being empty.
            ralf.gebhardt Ralf Gebhardt added a comment -

            Hi rucha174, as discussed with serg please change the order to

            <timestamp> <thread_id> <user> <db> <error>
            

            I am reopening the ticket

            ralf.gebhardt Ralf Gebhardt added a comment - Hi rucha174 , as discussed with serg please change the order to <timestamp> <thread_id> <user> <db> <error> I am reopening the ticket
            rucha174 Rucha Deodhar added a comment -

            made changes to format of log. fixed and pushed to 10.6

            rucha174 Rucha Deodhar added a comment - made changes to format of log. fixed and pushed to 10.6

            People

              rucha174 Rucha Deodhar
              Richard Richard Stracke
              Votes:
              1 Vote for this issue
              Watchers:
              13 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.