MySQL 8.4.3
Source Code Documentation
json_diff.h File Reference

Header file for the Json_diff class. More...

#include <stddef.h>
#include <algorithm>
#include <memory>
#include <optional>
#include <vector>
#include "sql-common/json_path.h"
#include "sql/mem_root_allocator.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...
 
struct  ReadJsonDiffResult
 The result of a call to read_json_diff(). 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_diff(). More...
 

Functions

enum_json_diff_status apply_json_diff (const Json_diff &diff, Json_dom *dom)
 Apply one JSON diff to the DOM provided. More...
 
std::optional< ReadJsonDiffResultread_json_diff (const unsigned char *pos, size_t length)
 Read one JSON diff from a buffer. 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_diff().

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_diff()

enum_json_diff_status apply_json_diff ( const Json_diff diff,
Json_dom dom 
)

Apply one JSON diff to the DOM provided.

Parameters
diffThe diff which contains the path to apply it and the new value.
domThe DOM to apply the diff to.
Returns
An enum_json_diff_status value that tells if the diff was applied successfully.

◆ read_json_diff()

std::optional< ReadJsonDiffResult > read_json_diff ( const unsigned char *  pos,
size_t  length 
)

Read one JSON diff from a buffer.

Parameters
posThe position to start reading from in the buffer. When the function returns, it will be set to the position right after the last byte read.
lengthThe maximum number of bytes to read from the buffer.
Returns
An object containing the Json_diff value and the number of bytes read, if successful. An empty value if an error was raised, or if the buffer did not contain a valid diff.

Variable Documentation

◆ JSON_DIFF_OPERATION_COUNT

const int JSON_DIFF_OPERATION_COUNT = 3
static

The number of elements of the enumeration above.