MySQL 8.0.40
Source Code Documentation
json_diff.h File Reference

Header file for the Json_diff class. More...

#include <stddef.h>
#include <algorithm>
#include <memory>
#include <vector>
#include "sql-common/json_path.h"
#include "sql/mem_root_allocator.h"
#include "sql/psi_memory_key.h"

Go to the source code of this file.

Classes

class  Json_diff
 A class that represents a logical change to a JSON document. More...
 
class  Json_diff_vector
 Vector of logical diffs describing changes to a JSON column. More...
 

Enumerations

enum class  enum_json_diff_operation { REPLACE , INSERT , REMOVE }
 Enum that describes what kind of operation a Json_diff object represents. More...
 
enum class  enum_json_diff_status { SUCCESS , ERROR , REJECTED }
 The result of applying JSON diffs on a JSON value using apply_json_diffs(). More...
 

Functions

enum_json_diff_status apply_json_diffs (Field_json *field, const Json_diff_vector *diffs)
 Apply a sequence of JSON diffs to the value stored in a JSON column. More...
 

Variables

static const int JSON_DIFF_OPERATION_COUNT = 3
 The number of elements of the enumeration above. More...
 

Detailed Description

Header file for the Json_diff class.

The Json_diff class is used to represent a logical change in a JSON column, so that a replication master can send only what has changed, instead of sending the whole new value to the replication slave when a JSON column is updated.

Enumeration Type Documentation

◆ enum_json_diff_operation

enum class enum_json_diff_operation
strong

Enum that describes what kind of operation a Json_diff object represents.

Enumerator
REPLACE 

The JSON value in the given path is replaced with a new value.

It has the same effect as JSON_REPLACE(col, path, value).

INSERT 

Add a new element at the given path.

If the path specifies an array element, it has the same effect as JSON_ARRAY_INSERT(col, path, value).

If the path specifies an object member, it has the same effect as JSON_INSERT(col, path, value).

REMOVE 

The JSON value at the given path is removed from an array or object.

It has the same effect as JSON_REMOVE(col, path).

◆ enum_json_diff_status

enum class enum_json_diff_status
strong

The result of applying JSON diffs on a JSON value using apply_json_diffs().

Enumerator
SUCCESS 

The JSON diffs were applied and the JSON value in the column was updated successfully.

ERROR 

An error was raised while applying one of the diffs.

The value in the column was not updated.

REJECTED 

One of the diffs was rejected.

This could happen if the path specified in the diff does not exist in the JSON value, or if the diff is supposed to add a new value at a given path, but there already is a value at the path.

This return code would usually indicate that the replication slave where the diff is applied, is out of sync with the replication master where the diff was created.

The value in the column was not updated, but no error was raised.

Function Documentation

◆ apply_json_diffs()

enum_json_diff_status apply_json_diffs ( Field_json field,
const Json_diff_vector diffs 
)

Apply a sequence of JSON diffs to the value stored in a JSON column.

Parameters
fieldthe column to update
diffsthe diffs to apply
Returns
an enum_json_diff_status value that tells if the diffs were applied successfully

Variable Documentation

◆ JSON_DIFF_OPERATION_COUNT

const int JSON_DIFF_OPERATION_COUNT = 3
static

The number of elements of the enumeration above.