[MDEV-31187] Add class Sql_mode_save_for_frm_handling Created: 2023-05-04  Updated: 2023-10-23  Resolved: 2023-10-23

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Fix Version/s: 10.4.32, 10.5.23, 10.6.16, 10.9.8, 10.11.6, 11.0.4, 11.1.3, 11.2.2, 11.3.1

Type: Task Priority: Critical
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-27744 LPAD in vcol created in ORACLE mode m... Closed

 Description   

To fix MDEV-27744 and to remove duplicate code, let's add a new class as follows:

/*
  Save the current sql_mode. Switch off sql_mode flags which can prevent
  normal parsing of VIEWs, expressions in generated columns.
  Restore the old sql_mode on destructor.
*/
class Sql_mode_save_for_frm_handling: public Sql_mode_save
{
public:
  Sql_mode_save_for_frm_handling(THD *thd)
   :Sql_mode_save(thd)
  {
    /*
      - MODE_REAL_AS_FLOAT            affect only CREATE TABLE parsing
      + MODE_PIPES_AS_CONCAT          affect expression parsing
      + MODE_ANSI_QUOTES              affect expression parsing
      + MODE_IGNORE_SPACE             affect expression parsing
      - MODE_IGNORE_BAD_TABLE_OPTIONS affect only CREATE/ALTER TABLE parsing
      * MODE_ONLY_FULL_GROUP_BY       affect execution
      * MODE_NO_UNSIGNED_SUBTRACTION  affect execution
      - MODE_NO_DIR_IN_CREATE         affect table creation only
      - MODE_POSTGRESQL               compounded from other modes
      + MODE_ORACLE                   affects Item creation (e.g for CONCAT)
      - MODE_MSSQL                    compounded from other modes
      - MODE_DB2                      compounded from other modes
      - MODE_MAXDB                    affect only CREATE TABLE parsing
      - MODE_NO_KEY_OPTIONS           affect only SHOW
      - MODE_NO_TABLE_OPTIONS         affect only SHOW
      - MODE_NO_FIELD_OPTIONS         affect only SHOW
      - MODE_MYSQL323                 affect only SHOW
      - MODE_MYSQL40                  affect only SHOW
      - MODE_ANSI                     compounded from other modes
                                      (+ transaction mode)
      ? MODE_NO_AUTO_VALUE_ON_ZERO    affect UPDATEs
      + MODE_NO_BACKSLASH_ESCAPES     affect expression parsing
      + MODE_EMPTY_STRING_IS_NULL     affect expression parsing
    */
    thd->variables.sql_mode&= ~(MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES |
                                MODE_IGNORE_SPACE | MODE_NO_BACKSLASH_ESCAPES |
                                MODE_ORACLE | MODE_EMPTY_STRING_IS_NULL);
  };
};

and reuse it in all places where we reset sql_mode for unambiguous and equal re-parsing.

Currently there are multiple places resetting different sql_mode flags, e.g.:

generate_partition_syntax_for_frm:
  sql_mode_t old_mode= thd->variables.sql_mode;
  thd->variables.sql_mode &= ~MODE_ANSI_QUOTES;
 
mysql_register_view:
    sql_mode_t sql_mode= thd->variables.sql_mode & MODE_ANSI_QUOTES;
    thd->variables.sql_mode&= ~MODE_ANSI_QUOTES;
 
 
mysql_make_view:
    thd->variables.sql_mode&= ~(MODE_PIPES_AS_CONCAT | MODE_ANSI_QUOTES |
                                MODE_IGNORE_SPACE | MODE_NO_BACKSLASH_ESCAPES |
                                MODE_ORACLE);
parse_vcol_defs:
  thd->variables.sql_mode &= ~(MODE_NO_BACKSLASH_ESCAPES | MODE_EMPTY_STRING_IS_NULL);
 
build_frm_image:
  sql_mode_t save_sql_mode= thd->variables.sql_mode;
  thd->variables.sql_mode &= ~MODE_ANSI_QUOTES;

/



 Comments   
Comment by Alexander Barkov [ 2023-08-31 ]

Hello Sergei Golubchik, please find the latest patch here:

https://github.com/MariaDB/server/commits/bb-10.4-bar-MDEV-27744-v2

There are three patches in this branch:
MDEV-31184
MDEV-31187
MDEV-27744

Thanks.

Comment by Sergei Golubchik [ 2023-10-21 ]

ok to push

Generated at Thu Feb 08 10:21:56 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.