Bug #87734 Replication does not handle NULL inserted in JSON NOT NULL column correctly
Submitted: 12 Sep 2017 9:02 Modified: 6 Oct 2017 18:14
Reporter: Sven Sandberg Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Replication Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[12 Sep 2017 9:02] Sven Sandberg
Description:
It is possible to insert a NULL value in a JSON NOT NULL column, using e.g. INSERT IGNORE or non-strict mode:

CREATE TABLE t (i INT, j JSON NOT NULL);
INSERT INTO t VALUES (1, NULL); # generates a warning, but succeeds

Internally, this value is stored as an empty string, and it is displayed as a JSON 'null' literal. However, the native functions to parse binary JSON values does not recognize this format. In much server code we have special cases for this, but not in replication code yet.

How to repeat:
--source include/have_binlog_format_row.inc
--source include/master-slave.inc
--source include/have_grep.inc

CREATE TABLE t (i INT, j JSON NOT NULL);

SET SESSION binlog_row_value_options = 'PARTIAL_JSON';
--source include/save_binlog_position.inc
INSERT IGNORE INTO t VALUES (1, NULL);
SELECT * FROM t;
--let $mysqlbinlog_only_decoded_rows=1
--source include/mysqlbinlog.inc

--source include/sync_slave_sql_with_master.inc

SELECT * FROM t;
[6 Oct 2017 18:14] Paul Dubois
Posted by developer:
 
Fixed in 8.0.4.

Handling of empty JSON documents has been made more robust.
[24 Oct 2017 14:17] Margaret Fisher
Changelog entry tagged.