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

Replication does not take into account SET STATEMENT

Details

    Description

      Refined and complete description
      ================================

      While SET STATEMENT @@session.var1=v1, ..., @@session.var_n=vn Query,
      when binlog_format = STATEMENT, is binlogged in verbatim the results of the Query execution are different between master (primary) and slave (replica).
      Unlike master, the slave side refuses to adopt var_1, ..., var_n customization, and
      which is the case of either DML and DDL queries.

      Even though that is by design the behavior does not allow for replicating correctly queries that either implicitly depend on session variables whose values are not included into Query_log_event, like

      SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);

      (on slave the replicated table may not be of Aria type)
      or the set-statement's query is composed with referencing variables explicitly e.g

      SET STATEMENT query_alloc_block_size = 1024 FOR INSERT INTO t_heap SET i=@@session.query_alloc_block_size + 1;

      (on slave the inserted value of i will be the slave's @@global.query_alloc_block_size + 1)
      Note that employing a separate SET @@session.var = value to prepend Query may not be (it *is* not for the two above cases) a workaround for statement binlog format replication either.

      To fix the issue beyond suggested Query re-writing, Monty and others considered effectively lift the design's constrain.

      After all it looks to be grounded solely on pessimistic assessments of 'security issues' at the slave side execution

      F-10: Replication: Slave threads will ignore SET_VAR hints to avoids security
      issues since slave threads run as root, avoids potential problems with
      variables replicated with SBR.

      Apparently it's far from being so dramatic as the above examples may hint. Specifically storage_engine,query_alloc_block_size and lots of other are security safe.

      I suggest to indeed *revise* that decision, and when that's done *introduce* for backward compatibility a slave side switch. Along that let's also *attend* MDEV-27462 which must review the current list of disallowed variables (in particular consider to append to it binlog_format which is disallowed to change within transaction context which may not be the case on master but it may be so on slave).

      With this measure we also achieve (addresses knielsen's note) consistent results between the slave applier and the binlog "direct" applier executions.
      The replicated with session-variables SET-STATEMENT-FOR-Query could be engaged further on cases when correctness can be accomplished (addresses monty's note) only with more reach execution context than currently Query_log_event is provided with.


      *Former Elena's description:*

      DDL statements sent to slave does not take into account the original environment where the query was executed.
      This is true when using SET STATEMENT or having a non standard value for any variable that is internally used by a DDL, like default_storage_engine.

      --source include/master-slave.inc
       
      SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);
      SHOW CREATE TABLE t;
       
      --sync_slave_with_master
      SHOW CREATE TABLE t;
       
      --connection master
      DROP TABLE t;
      --source include/rpl_end.inc
      


      Result

      [connection master]
      SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);
      SHOW CREATE TABLE t;
      Table	Create Table
      t	CREATE TABLE `t` (
        `i` int(11) DEFAULT NULL
      ) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
      connection slave;
      SHOW CREATE TABLE t;
      Table	Create Table
      t	CREATE TABLE `t` (
        `i` int(11) DEFAULT NULL
      ) ENGINE=MyISAM DEFAULT CHARSET=latin1
      

      Attachments

        Issue Links

          Activity

            elenst Elena Stepanova created issue -
            Elkin Andrei Elkin made changes -
            Field Original Value New Value
            Assignee Andrei Elkin [ elkin ] Sujatha Sivakumar [ sujatha.sivakumar ]
            sujatha.sivakumar Sujatha Sivakumar (Inactive) made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            sujatha.sivakumar Sujatha Sivakumar (Inactive) made changes -
            Assignee Sujatha Sivakumar [ sujatha.sivakumar ] Andrei Elkin [ elkin ]
            Status In Progress [ 3 ] In Review [ 10002 ]
            Elkin Andrei Elkin made changes -
            Assignee Andrei Elkin [ elkin ] Sujatha Sivakumar [ sujatha.sivakumar ]
            Status In Review [ 10002 ] Stalled [ 10000 ]
            sujatha.sivakumar Sujatha Sivakumar (Inactive) made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]
            sujatha.sivakumar Sujatha Sivakumar (Inactive) made changes -
            Status In Progress [ 3 ] Stalled [ 10000 ]
            sujatha.sivakumar Sujatha Sivakumar (Inactive) made changes -
            Labels decide_logging_format
            julien.fritsch Julien Fritsch made changes -
            Fix Version/s 10.1 [ 16100 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 84594 ] MariaDB v4 [ 143524 ]
            Elkin Andrei Elkin made changes -
            Assignee Sujatha Sivakumar [ sujatha.sivakumar ] Andrei Elkin [ elkin ]
            niljoshi Nilnandan Joshi made changes -
            Affects Version/s 10.6 [ 24028 ]
            Elkin Andrei Elkin made changes -
            julien.fritsch Julien Fritsch made changes -
            Priority Major [ 3 ] Critical [ 2 ]
            monty Michael Widenius made changes -
            Description {code:sql}
            --source include/master-slave.inc

            SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);
            SHOW CREATE TABLE t;

            --sync_slave_with_master
            SHOW CREATE TABLE t;

            --connection master
            DROP TABLE t;
            --source include/rpl_end.inc
            {code}
            {code:sql|title=Result}
            [connection master]
            SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);
            SHOW CREATE TABLE t;
            Table Create Table
            t CREATE TABLE `t` (
              `i` int(11) DEFAULT NULL
            ) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
            connection slave;
            SHOW CREATE TABLE t;
            Table Create Table
            t CREATE TABLE `t` (
              `i` int(11) DEFAULT NULL
            ) ENGINE=MyISAM DEFAULT CHARSET=latin1
            {code}
            DDL statements sent to slave does not take into account the original environment where the query was executed.
            This is true when using SET STATEMENT or having a non standard value for any variable that is internally used by a DDL, like default_storage_engine.

            {code:sql}
            --source include/master-slave.inc

            SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);
            SHOW CREATE TABLE t;

            --sync_slave_with_master
            SHOW CREATE TABLE t;

            --connection master
            DROP TABLE t;
            --source include/rpl_end.inc
            {code}
            {code:sql|title=Result}
            [connection master]
            SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);
            SHOW CREATE TABLE t;
            Table Create Table
            t CREATE TABLE `t` (
              `i` int(11) DEFAULT NULL
            ) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
            connection slave;
            SHOW CREATE TABLE t;
            Table Create Table
            t CREATE TABLE `t` (
              `i` int(11) DEFAULT NULL
            ) ENGINE=MyISAM DEFAULT CHARSET=latin1
            {code}
            Elkin Andrei Elkin made changes -
            Fix Version/s 10.4 [ 22408 ]
            Fix Version/s 10.2 [ 14601 ]
            monty Michael Widenius made changes -
            mariadb-jira-automation Jira Automation (IT) made changes -
            Zendesk Related Tickets 201617
            Zendesk active tickets 201617
            bnestere Brandon Nesterenko made changes -
            Assignee Andrei Elkin [ elkin ] Dave Gosselin [ JIRAUSER52216 ]
            Elkin Andrei Elkin made changes -
            Assignee Dave Gosselin [ JIRAUSER52216 ] Andrei Elkin [ elkin ]
            julien.fritsch Julien Fritsch made changes -
            Fix Version/s 10.5 [ 23123 ]
            Fix Version/s 10.6 [ 24028 ]
            Fix Version/s 10.11 [ 27614 ]
            Fix Version/s 11.4 [ 29301 ]
            Fix Version/s 11.7 [ 29815 ]
            Fix Version/s 10.4(EOL) [ 22408 ]
            Elkin Andrei Elkin made changes -
            Description DDL statements sent to slave does not take into account the original environment where the query was executed.
            This is true when using SET STATEMENT or having a non standard value for any variable that is internally used by a DDL, like default_storage_engine.

            {code:sql}
            --source include/master-slave.inc

            SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);
            SHOW CREATE TABLE t;

            --sync_slave_with_master
            SHOW CREATE TABLE t;

            --connection master
            DROP TABLE t;
            --source include/rpl_end.inc
            {code}
            {code:sql|title=Result}
            [connection master]
            SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);
            SHOW CREATE TABLE t;
            Table Create Table
            t CREATE TABLE `t` (
              `i` int(11) DEFAULT NULL
            ) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
            connection slave;
            SHOW CREATE TABLE t;
            Table Create Table
            t CREATE TABLE `t` (
              `i` int(11) DEFAULT NULL
            ) ENGINE=MyISAM DEFAULT CHARSET=latin1
            {code}
            Refined and complete description
            ================================

            While [SET STATEMENT @@session.var1=v1, ..., @@session.var_n=vn Query|https://mariadb.com/kb/en/set-statement],
            when {{binlog_format = STATEMENT}}, is binlogged in verbatim the results of the {{Query}} execution are different between master (primary) and slave (replica).
            Unlike master, the slave side refuses to adopt {{var_1, ..., var_n}}
            which is the case of either DML and DDL queries.
            Even though that is by [design|https://dev.mysql.com/worklog/task/?id=681]
            the behavior does not allow for replicating correctly queries that either implicitly
            depend on session variables whose values are not included into
            {{Query_log_event}}, like

               SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);

            (on slave the replicated table may not be of Aria type)
            or the set-statement's query is composed to reference variables explicitly
            e.g

               SET STATEMENT query_alloc_block_size = 1024 FOR INSERT INTO t_heap SET i=@@session.query_alloc_block_size + 1;

            (on slave the inserted value of {{i}} will be the slave's {{@@global.query_alloc_block_size + 1}})
            Note that employing a separate {{SET @@session.var = value}} to
            prepend {{Query}} may not be (it **is** not for the two above cases) a workaround for statement binlog format
            replication either.

            To fix the issue beyond [suggested Query re-writing|https://jira.mariadb.org/browse/MDEV-14760?focusedCommentId=295308&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-295308],
            Monty and others considered effectively lift the design's constrain.

            After all it looks to be grounded solely on pessimistic assessments
            of 'security issues' at the slave side execution

            {quote}F-10: Replication: Slave threads will ignore SET_VAR hints to avoids security
                 issues since slave threads run as root, avoids potential problems with
                 variables replicated with SBR.
            {quote}
            Apparently it's far from being so dramatic as the above
            examples may hint. Specifically {{storage_engine,query_alloc_block_size}} and lots of other are security safe.

            I suggest to indeed **revise** that decision, and when that's done
            **introduce** for backward compatibility a slave side switch.
            Along that let's also **attend** MDEV-27462 which must review the current
            list of disallowed variables (in particular consider to append to it
            {{binlog_format}} which is disallowed to change within transaction
            context which may not be the case on master but it may be so on slave).

            With this measure we also [achieve| consistent results between the slave applier and the binlog "direct" applier executions.
            The replicated with session-variables {{SET-STATEMENT-FOR-Query}} could be engaged further on cases when correctness can be achieve only with more reach execution context than currently {{Query_log_event}} is provided with.
            {color:#C1C7D0}
            **Former Elena's description:**

            DDL statements sent to slave does not take into account the original environment where the query was executed.
            This is true when using SET STATEMENT or having a non standard value for any variable that is internally used by a DDL, like default_storage_engine.

            {code:sql}
            --source include/master-slave.inc

            SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);
            SHOW CREATE TABLE t;

            --sync_slave_with_master
            SHOW CREATE TABLE t;

            --connection master
            DROP TABLE t;
            --source include/rpl_end.inc
            {code}
            {code:sql|title=Result}
            [connection master]
            SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);
            SHOW CREATE TABLE t;
            Table Create Table
            t CREATE TABLE `t` (
              `i` int(11) DEFAULT NULL
            ) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
            connection slave;
            SHOW CREATE TABLE t;
            Table Create Table
            t CREATE TABLE `t` (
              `i` int(11) DEFAULT NULL
            ) ENGINE=MyISAM DEFAULT CHARSET=latin1
            {code}{color}
            Elkin Andrei Elkin made changes -
            Description Refined and complete description
            ================================

            While [SET STATEMENT @@session.var1=v1, ..., @@session.var_n=vn Query|https://mariadb.com/kb/en/set-statement],
            when {{binlog_format = STATEMENT}}, is binlogged in verbatim the results of the {{Query}} execution are different between master (primary) and slave (replica).
            Unlike master, the slave side refuses to adopt {{var_1, ..., var_n}}
            which is the case of either DML and DDL queries.
            Even though that is by [design|https://dev.mysql.com/worklog/task/?id=681]
            the behavior does not allow for replicating correctly queries that either implicitly
            depend on session variables whose values are not included into
            {{Query_log_event}}, like

               SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);

            (on slave the replicated table may not be of Aria type)
            or the set-statement's query is composed to reference variables explicitly
            e.g

               SET STATEMENT query_alloc_block_size = 1024 FOR INSERT INTO t_heap SET i=@@session.query_alloc_block_size + 1;

            (on slave the inserted value of {{i}} will be the slave's {{@@global.query_alloc_block_size + 1}})
            Note that employing a separate {{SET @@session.var = value}} to
            prepend {{Query}} may not be (it **is** not for the two above cases) a workaround for statement binlog format
            replication either.

            To fix the issue beyond [suggested Query re-writing|https://jira.mariadb.org/browse/MDEV-14760?focusedCommentId=295308&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-295308],
            Monty and others considered effectively lift the design's constrain.

            After all it looks to be grounded solely on pessimistic assessments
            of 'security issues' at the slave side execution

            {quote}F-10: Replication: Slave threads will ignore SET_VAR hints to avoids security
                 issues since slave threads run as root, avoids potential problems with
                 variables replicated with SBR.
            {quote}
            Apparently it's far from being so dramatic as the above
            examples may hint. Specifically {{storage_engine,query_alloc_block_size}} and lots of other are security safe.

            I suggest to indeed **revise** that decision, and when that's done
            **introduce** for backward compatibility a slave side switch.
            Along that let's also **attend** MDEV-27462 which must review the current
            list of disallowed variables (in particular consider to append to it
            {{binlog_format}} which is disallowed to change within transaction
            context which may not be the case on master but it may be so on slave).

            With this measure we also [achieve| consistent results between the slave applier and the binlog "direct" applier executions.
            The replicated with session-variables {{SET-STATEMENT-FOR-Query}} could be engaged further on cases when correctness can be achieve only with more reach execution context than currently {{Query_log_event}} is provided with.
            {color:#C1C7D0}
            **Former Elena's description:**

            DDL statements sent to slave does not take into account the original environment where the query was executed.
            This is true when using SET STATEMENT or having a non standard value for any variable that is internally used by a DDL, like default_storage_engine.

            {code:sql}
            --source include/master-slave.inc

            SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);
            SHOW CREATE TABLE t;

            --sync_slave_with_master
            SHOW CREATE TABLE t;

            --connection master
            DROP TABLE t;
            --source include/rpl_end.inc
            {code}
            {code:sql|title=Result}
            [connection master]
            SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);
            SHOW CREATE TABLE t;
            Table Create Table
            t CREATE TABLE `t` (
              `i` int(11) DEFAULT NULL
            ) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
            connection slave;
            SHOW CREATE TABLE t;
            Table Create Table
            t CREATE TABLE `t` (
              `i` int(11) DEFAULT NULL
            ) ENGINE=MyISAM DEFAULT CHARSET=latin1
            {code}{color}
            Refined and complete description
            ================================

            While [SET STATEMENT @@session.var1=v1, ..., @@session.var_n=vn Query|https://mariadb.com/kb/en/set-statement],
            when {{binlog_format = STATEMENT}}, is binlogged in verbatim the results of the {{Query}} execution are different between master (primary) and slave (replica).
            Unlike master, the slave side refuses to adopt {{var_1, ..., var_n}}
            which is the case of either DML and DDL queries.
            Even though that is by [design|https://dev.mysql.com/worklog/task/?id=681]
            the behavior does not allow for replicating correctly queries that either implicitly
            depend on session variables whose values are not included into
            {{Query_log_event}}, like

               SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);

            (on slave the replicated table may not be of Aria type)
            or the set-statement's query is composed to reference variables explicitly
            e.g

               SET STATEMENT query_alloc_block_size = 1024 FOR INSERT INTO t_heap SET i=@@session.query_alloc_block_size + 1;

            (on slave the inserted value of {{i}} will be the slave's {{@@global.query_alloc_block_size + 1}})
            Note that employing a separate {{SET @@session.var = value}} to
            prepend {{Query}} may not be (it **is** not for the two above cases) a workaround for statement binlog format
            replication either.

            To fix the issue beyond [suggested Query re-writing|https://jira.mariadb.org/browse/MDEV-14760?focusedCommentId=295308&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-295308],
            Monty and others considered effectively lift the design's constrain.

            After all it looks to be grounded solely on pessimistic assessments
            of 'security issues' at the slave side execution

            {quote}F-10: Replication: Slave threads will ignore SET_VAR hints to avoids security
                 issues since slave threads run as root, avoids potential problems with
                 variables replicated with SBR.
            {quote}
            Apparently it's far from being so dramatic as the above
            examples may hint. Specifically {{storage_engine,query_alloc_block_size}} and lots of other are security safe.

            I suggest to indeed **revise** that decision, and when that's done
            **introduce** for backward compatibility a slave side switch.
            Along that let's also **attend** MDEV-27462 which must review the current
            list of disallowed variables (in particular consider to append to it
            {{binlog_format}} which is disallowed to change within transaction
            context which may not be the case on master but it may be so on slave).

            With this measure we also [achieve|https://jira.mariadb.org/browse/MDEV-14760?focusedCommentId=295308&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-295308] (addresses [~knielsen]'s note) consistent results between the slave applier and the binlog "direct" applier executions.
            The replicated with session-variables {{SET-STATEMENT-FOR-Query}} could be engaged further on cases when correctness can be accomplished only with more reach execution context than currently {{Query_log_event}} is provided with.

            {color:#C1C7D0}
            **Former Elena's description:**

            DDL statements sent to slave does not take into account the original environment where the query was executed.
            This is true when using SET STATEMENT or having a non standard value for any variable that is internally used by a DDL, like default_storage_engine.

            {code:sql}
            --source include/master-slave.inc

            SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);
            SHOW CREATE TABLE t;

            --sync_slave_with_master
            SHOW CREATE TABLE t;

            --connection master
            DROP TABLE t;
            --source include/rpl_end.inc
            {code}
            {code:sql|title=Result}
            [connection master]
            SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);
            SHOW CREATE TABLE t;
            Table Create Table
            t CREATE TABLE `t` (
              `i` int(11) DEFAULT NULL
            ) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
            connection slave;
            SHOW CREATE TABLE t;
            Table Create Table
            t CREATE TABLE `t` (
              `i` int(11) DEFAULT NULL
            ) ENGINE=MyISAM DEFAULT CHARSET=latin1
            {code}{color}
            Elkin Andrei Elkin made changes -
            Description Refined and complete description
            ================================

            While [SET STATEMENT @@session.var1=v1, ..., @@session.var_n=vn Query|https://mariadb.com/kb/en/set-statement],
            when {{binlog_format = STATEMENT}}, is binlogged in verbatim the results of the {{Query}} execution are different between master (primary) and slave (replica).
            Unlike master, the slave side refuses to adopt {{var_1, ..., var_n}}
            which is the case of either DML and DDL queries.
            Even though that is by [design|https://dev.mysql.com/worklog/task/?id=681]
            the behavior does not allow for replicating correctly queries that either implicitly
            depend on session variables whose values are not included into
            {{Query_log_event}}, like

               SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);

            (on slave the replicated table may not be of Aria type)
            or the set-statement's query is composed to reference variables explicitly
            e.g

               SET STATEMENT query_alloc_block_size = 1024 FOR INSERT INTO t_heap SET i=@@session.query_alloc_block_size + 1;

            (on slave the inserted value of {{i}} will be the slave's {{@@global.query_alloc_block_size + 1}})
            Note that employing a separate {{SET @@session.var = value}} to
            prepend {{Query}} may not be (it **is** not for the two above cases) a workaround for statement binlog format
            replication either.

            To fix the issue beyond [suggested Query re-writing|https://jira.mariadb.org/browse/MDEV-14760?focusedCommentId=295308&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-295308],
            Monty and others considered effectively lift the design's constrain.

            After all it looks to be grounded solely on pessimistic assessments
            of 'security issues' at the slave side execution

            {quote}F-10: Replication: Slave threads will ignore SET_VAR hints to avoids security
                 issues since slave threads run as root, avoids potential problems with
                 variables replicated with SBR.
            {quote}
            Apparently it's far from being so dramatic as the above
            examples may hint. Specifically {{storage_engine,query_alloc_block_size}} and lots of other are security safe.

            I suggest to indeed **revise** that decision, and when that's done
            **introduce** for backward compatibility a slave side switch.
            Along that let's also **attend** MDEV-27462 which must review the current
            list of disallowed variables (in particular consider to append to it
            {{binlog_format}} which is disallowed to change within transaction
            context which may not be the case on master but it may be so on slave).

            With this measure we also [achieve|https://jira.mariadb.org/browse/MDEV-14760?focusedCommentId=295308&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-295308] (addresses [~knielsen]'s note) consistent results between the slave applier and the binlog "direct" applier executions.
            The replicated with session-variables {{SET-STATEMENT-FOR-Query}} could be engaged further on cases when correctness can be accomplished only with more reach execution context than currently {{Query_log_event}} is provided with.

            {color:#C1C7D0}
            **Former Elena's description:**

            DDL statements sent to slave does not take into account the original environment where the query was executed.
            This is true when using SET STATEMENT or having a non standard value for any variable that is internally used by a DDL, like default_storage_engine.

            {code:sql}
            --source include/master-slave.inc

            SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);
            SHOW CREATE TABLE t;

            --sync_slave_with_master
            SHOW CREATE TABLE t;

            --connection master
            DROP TABLE t;
            --source include/rpl_end.inc
            {code}
            {code:sql|title=Result}
            [connection master]
            SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);
            SHOW CREATE TABLE t;
            Table Create Table
            t CREATE TABLE `t` (
              `i` int(11) DEFAULT NULL
            ) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
            connection slave;
            SHOW CREATE TABLE t;
            Table Create Table
            t CREATE TABLE `t` (
              `i` int(11) DEFAULT NULL
            ) ENGINE=MyISAM DEFAULT CHARSET=latin1
            {code}{color}
            Refined and complete description
            ================================

            While [SET STATEMENT @@session.var1=v1, ..., @@session.var_n=vn Query|https://mariadb.com/kb/en/set-statement],
            when {{binlog_format = STATEMENT}}, is binlogged in verbatim the results of the {{Query}} execution are different between master (primary) and slave (replica).
            Unlike master, the slave side refuses to adopt {{var_1, ..., var_n}} customization, and
            which is the case of either DML and DDL queries.

            Even though that is by [design|https://dev.mysql.com/worklog/task/?id=681] the behavior does not allow for replicating correctly queries that either implicitly depend on session variables whose values are not included into {{Query_log_event}}, like

               SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);

            (on slave the replicated table may not be of Aria type)
            or the set-statement's query is composed with referencing variables explicitly e.g

               SET STATEMENT query_alloc_block_size = 1024 FOR INSERT INTO t_heap SET i=@@session.query_alloc_block_size + 1;

            (on slave the inserted value of {{i}} will be the slave's {{@@global.query_alloc_block_size + 1}})
            Note that employing a separate {{SET @@session.var = value}} to prepend {{Query}} may not be (it **is** not for the two above cases) a workaround for statement binlog format replication either.

            To fix the issue beyond [suggested Query re-writing|https://jira.mariadb.org/browse/MDEV-14760?focusedCommentId=295308&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-295308], Monty and others considered effectively lift the design's constrain.

            After all it looks to be grounded solely on pessimistic assessments of 'security issues' at the slave side execution

            {quote}F-10: Replication: Slave threads will ignore SET_VAR hints to avoids security
                 issues since slave threads run as root, avoids potential problems with
                 variables replicated with SBR.
            {quote}
            Apparently it's far from being so dramatic as the above examples may hint. Specifically {{storage_engine,query_alloc_block_size}} and lots of other are security safe.

            I suggest to indeed **revise** that decision, and when that's done **introduce** for backward compatibility a slave side switch. Along that let's also **attend** MDEV-27462 which must review the current list of disallowed variables (in particular consider to append to it {{binlog_format}} which is disallowed to change within transaction context which may not be the case on master but it may be so on slave).

            With this measure we also [achieve|https://jira.mariadb.org/browse/MDEV-14760?focusedCommentId=295308&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-295308] (addresses [~knielsen]'s note) consistent results between the slave applier and the binlog "direct" applier executions.
            The replicated with session-variables {{SET-STATEMENT-FOR-Query}} could be engaged further on cases when correctness can be accomplished (addresses [~monty]'s [note|https://jira.mariadb.org/browse/MDEV-14760?focusedCommentId=268767&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-268767]) only with more reach execution context than currently {{Query_log_event}} is provided with.

            {color:#C1C7D0}
            **Former Elena's description:**

            DDL statements sent to slave does not take into account the original environment where the query was executed.
            This is true when using SET STATEMENT or having a non standard value for any variable that is internally used by a DDL, like default_storage_engine.

            {code:sql}
            --source include/master-slave.inc

            SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);
            SHOW CREATE TABLE t;

            --sync_slave_with_master
            SHOW CREATE TABLE t;

            --connection master
            DROP TABLE t;
            --source include/rpl_end.inc
            {code}
            {code:sql|title=Result}
            [connection master]
            SET STATEMENT storage_engine=Aria FOR CREATE TABLE t (i INT);
            SHOW CREATE TABLE t;
            Table Create Table
            t CREATE TABLE `t` (
              `i` int(11) DEFAULT NULL
            ) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
            connection slave;
            SHOW CREATE TABLE t;
            Table Create Table
            t CREATE TABLE `t` (
              `i` int(11) DEFAULT NULL
            ) ENGINE=MyISAM DEFAULT CHARSET=latin1
            {code}{color}
            Elkin Andrei Elkin made changes -
            Assignee Andrei Elkin [ elkin ] Kristian Nielsen [ knielsen ]
            knielsen Kristian Nielsen made changes -
            Status Stalled [ 10000 ] Open [ 1 ]
            knielsen Kristian Nielsen made changes -
            Status Open [ 1 ] Confirmed [ 10101 ]
            knielsen Kristian Nielsen made changes -
            Assignee Kristian Nielsen [ knielsen ]
            julien.fritsch Julien Fritsch made changes -
            Assignee Brandon Nesterenko [ JIRAUSER48702 ]
            julien.fritsch Julien Fritsch made changes -
            Fix Version/s 11.7(EOL) [ 29815 ]

            People

              bnestere Brandon Nesterenko
              elenst Elena Stepanova
              Votes:
              1 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

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