MySQL 8.4.2
Source Code Documentation
rem0cmp.cc File Reference

Comparison services for records. More...

#include <gstream.h>
#include <page0cur.h>
#include <spatial.h>
#include <sys/types.h>
#include <algorithm>
#include "ha_prototypes.h"
#include "handler0alter.h"
#include "mysql/strings/m_ctype.h"
#include "rem0cmp.h"
#include "srv0srv.h"

Namespaces

namespace  dd
 The version of the current data dictionary table definitions.
 

Functions

static int innobase_mysql_cmp (ulint prtype, const byte *a, size_t a_length, const byte *b, size_t b_length)
 Compare two data fields. More...
 
bool cmp_cols_are_equal (const dict_col_t *col1, const dict_col_t *col2, bool check_charsets)
 Returns true if two columns are equal for comparison purposes. More...
 
static UNIV_COLD int cmp_decimal (const byte *a, unsigned int a_length, const byte *b, unsigned int b_length, bool is_asc)
 Compare two DATA_DECIMAL (MYSQL_TYPE_DECIMAL) fields. More...
 
static int cmp_geometry_field (ulint prtype, const byte *a, unsigned int a_length, const byte *b, unsigned int b_length)
 Innobase uses this function to compare two geometry data fields. More...
 
static int cmp_gis_field (page_cur_mode_t mode, const byte *a, unsigned int a_length, const byte *b, unsigned int b_length, const dd::Spatial_reference_system *srs)
 Innobase uses this function to compare two gis data fields. More...
 
static int cmp_whole_field (ulint mtype, ulint prtype, bool is_asc, const byte *a, unsigned int a_length, const byte *b, unsigned int b_length)
 Compare two data fields. More...
 
int cmp_data (ulint mtype, ulint prtype, bool is_asc, const byte *data1, ulint len1, const byte *data2, ulint len2)
 Compare two data fields. More...
 
int cmp_dtuple_rec_with_gis (const dtuple_t *dtuple, const rec_t *rec, const ulint *offsets, page_cur_mode_t mode, const dd::Spatial_reference_system *srs)
 Compare a GIS data tuple to a physical record. More...
 
int cmp_dtuple_rec_with_gis_internal (const dtuple_t *dtuple, const rec_t *rec, const ulint *offsets, const dd::Spatial_reference_system *srs)
 Compare a GIS data tuple to a physical record in rtree non-leaf node. More...
 
int cmp_data_data (ulint mtype, ulint prtype, bool is_asc, const byte *data1, ulint len1, const byte *data2, ulint len2)
 Compare two data fields. More...
 
int cmp_dtuple_rec_with_match_low (const dtuple_t *dtuple, const rec_t *rec, const dict_index_t *index, const ulint *offsets, ulint n_cmp, ulint *matched_fields)
 Compare a data tuple to a physical record. More...
 
static ulint cmp_get_pad_char (const dtype_t *type)
 Get the pad character code point for a type. More...
 
int cmp_dtuple_rec_with_match_bytes (const dtuple_t *dtuple, const rec_t *rec, const dict_index_t *index, const ulint *offsets, ulint *matched_fields, ulint *matched_bytes)
 Compare a data tuple to a physical record. More...
 
int cmp_dtuple_rec (const dtuple_t *dtuple, const rec_t *rec, const dict_index_t *index, const ulint *offsets)
 Compare a data tuple to a physical record. More...
 
bool cmp_dtuple_is_prefix_of_rec (const dtuple_t *dtuple, const rec_t *rec, const dict_index_t *index, const ulint *offsets)
 Check if a dtuple is a prefix of a record. More...
 
static int cmp_rec_rec_simple_field (const rec_t *rec1, const rec_t *rec2, const ulint *offsets1, const ulint *offsets2, const dict_index_t *index, ulint n)
 Compare two physical record fields. More...
 
int cmp_rec_rec_simple (const rec_t *rec1, const rec_t *rec2, const ulint *offsets1, const ulint *offsets2, const dict_index_t *index, TABLE *table)
 Compare two physical records that contain the same number of columns, none of which are stored externally. More...
 
int cmp_rec_rec_with_match (const rec_t *rec1, const rec_t *rec2, const ulint *offsets1, const ulint *offsets2, const dict_index_t *index, bool spatial_index_non_leaf, bool nulls_unequal, ulint *matched_fields, bool cmp_btree_recs)
 Compare two B-tree records. More...
 

Detailed Description

Comparison services for records.

Created 7/1/1994 Heikki Tuuri

Function Documentation

◆ cmp_cols_are_equal()

bool cmp_cols_are_equal ( const dict_col_t col1,
const dict_col_t col2,
bool  check_charsets 
)

Returns true if two columns are equal for comparison purposes.

Parameters
[in]col1Column to compare.
[in]col2Column to compare.
[in]check_charsetsif true then check the character sets.
Returns
true if the columns are considered equal in comparisons. in: whether to check charsets

◆ cmp_data()

int cmp_data ( ulint  mtype,
ulint  prtype,
bool  is_asc,
const byte data1,
ulint  len1,
const byte data2,
ulint  len2 
)
inline

Compare two data fields.

Parameters
[in]mtypemain type
[in]prtypeprecise type
[in]is_asctrue=ascending, false=descending order
[in]data1data field
[in]len1length of data1 in bytes, or UNIV_SQL_NULL
[in]data2data field
[in]len2length of data2 in bytes, or UNIV_SQL_NULL
Returns
the comparison result of data1 and data2
Return values
0if data1 is equal to data2
negativeif data1 is less than data2
positiveif data1 is greater than data2

◆ cmp_data_data()

int cmp_data_data ( ulint  mtype,
ulint  prtype,
bool  is_asc,
const byte data1,
ulint  len1,
const byte data2,
ulint  len2 
)

Compare two data fields.

Parameters
[in]mtypemain type
[in]prtypeprecise type
[in]is_asctrue=ascending, false=descending order
[in]data1data field
[in]len1length of data1 in bytes, or UNIV_SQL_NULL
[in]data2data field
[in]len2length of data2 in bytes, or UNIV_SQL_NULL
Returns
the comparison result of data1 and data2
Return values
0if data1 is equal to data2
negativeif data1 is less than data2
positiveif data1 is greater than data2

◆ cmp_decimal()

static UNIV_COLD int cmp_decimal ( const byte a,
unsigned int  a_length,
const byte b,
unsigned int  b_length,
bool  is_asc 
)
static

Compare two DATA_DECIMAL (MYSQL_TYPE_DECIMAL) fields.

TODO: Remove this function. Everything should use MYSQL_TYPE_NEWDECIMAL.

Parameters
[in]adata field
[in]a_lengthlength of a, in bytes (not UNIV_SQL_NULL)
[in]bdata field
[in]b_lengthlength of b, in bytes (not UNIV_SQL_NULL)
[in]is_asctrue=ascending, false=descending order
Returns
positive, 0, negative, if a is greater, equal, less than b, respectively

◆ cmp_dtuple_is_prefix_of_rec()

bool cmp_dtuple_is_prefix_of_rec ( const dtuple_t dtuple,
const rec_t rec,
const dict_index_t index,
const ulint offsets 
)

Check if a dtuple is a prefix of a record.

Parameters
[in]dtupledata tuple
[in]recB-tree record
[in]indexB-tree index
[in]offsetsrec_get_offsets(rec)
Returns
true if prefix

◆ cmp_dtuple_rec()

int cmp_dtuple_rec ( const dtuple_t dtuple,
const rec_t rec,
const dict_index_t index,
const ulint offsets 
)

Compare a data tuple to a physical record.

See also
cmp_dtuple_rec_with_match
Parameters
[in]dtupledata tuple
[in]recrecord
[in]indexindex
[in]offsetsrec_get_offsets(rec)
Returns
the comparison result of dtuple and rec
Return values
0if dtuple is equal to rec
negativeif dtuple is less than rec
positiveif dtuple is greater than rec

◆ cmp_dtuple_rec_with_gis()

int cmp_dtuple_rec_with_gis ( const dtuple_t dtuple,
const rec_t rec,
const ulint offsets,
page_cur_mode_t  mode,
const dd::Spatial_reference_system srs 
)

Compare a GIS data tuple to a physical record.

Parameters
[in]dtupledata tuple
[in]recB-tree record
[in]offsetsrec_get_offsets(rec)
[in]modecompare mode
[in]srsSpatial reference system of R-tree
Return values
negativeif dtuple is less than rec

◆ cmp_dtuple_rec_with_gis_internal()

int cmp_dtuple_rec_with_gis_internal ( const dtuple_t dtuple,
const rec_t rec,
const ulint offsets,
const dd::Spatial_reference_system srs 
)

Compare a GIS data tuple to a physical record in rtree non-leaf node.

We need to check the page number field, since we don't store pk field in rtree non-leaf node.

Parameters
[in]dtupledata tuple
[in]recR-tree record
[in]offsetsrec_get_offsets(rec)
[in]srsSpatial referenxe system
Return values
negativeif dtuple is less than rec

◆ cmp_dtuple_rec_with_match_bytes()

int cmp_dtuple_rec_with_match_bytes ( const dtuple_t dtuple,
const rec_t rec,
const dict_index_t index,
const ulint offsets,
ulint matched_fields,
ulint matched_bytes 
)

Compare a data tuple to a physical record.

Parameters
[in]dtupledata tuple
[in]recB-tree or R-tree index record
[in]indexindex tree
[in]offsetsrec_get_offsets(rec)
[in,out]matched_fieldsnumber of completely matched fields
[in,out]matched_bytesnumber of matched bytes in the first field that is not matched
Returns
the comparison result of dtuple and rec
Return values
0if dtuple is equal to rec
negativeif dtuple is less than rec
positiveif dtuple is greater than rec

◆ cmp_dtuple_rec_with_match_low()

int cmp_dtuple_rec_with_match_low ( const dtuple_t dtuple,
const rec_t rec,
const dict_index_t index,
const ulint offsets,
ulint  n_cmp,
ulint matched_fields 
)

Compare a data tuple to a physical record.

Parameters
[in]dtupledata tuple
[in]recrecord
[in]indexindex
[in]offsetsrec_get_offsets(rec)
[in]n_cmpnumber of fields to compare
[in,out]matched_fieldsnumber of completely matched fields
Returns
the comparison result of dtuple and rec
Return values
0if dtuple is equal to rec
negativeif dtuple is less than rec
positiveif dtuple is greater than rec

◆ cmp_geometry_field()

static int cmp_geometry_field ( ulint  prtype,
const byte a,
unsigned int  a_length,
const byte b,
unsigned int  b_length 
)
static

Innobase uses this function to compare two geometry data fields.

Returns
1, 0, -1, if a is greater, equal, less than b, respectively
Parameters
prtypein: precise type
ain: data field
a_lengthin: data field length, not UNIV_SQL_NULL
bin: data field
b_lengthin: data field length, not UNIV_SQL_NULL

◆ cmp_get_pad_char()

static ulint cmp_get_pad_char ( const dtype_t type)
inlinestatic

Get the pad character code point for a type.

Parameters
[in]typeSQL data type
Returns
pad character code point
Return values
ULINT_UNDEFINEDif no padding is specified

◆ cmp_gis_field()

static int cmp_gis_field ( page_cur_mode_t  mode,
const byte a,
unsigned int  a_length,
const byte b,
unsigned int  b_length,
const dd::Spatial_reference_system srs 
)
static

Innobase uses this function to compare two gis data fields.

Returns
1, 0, -1, if mode == PAGE_CUR_MBR_EQUAL. And return 1, 0 for rest compare modes, depends on a and b qualifies the relationship (CONTAIN, WITHIN etc.)
Parameters
modein: compare mode
ain: data field
a_lengthin: data field length, not UNIV_SQL_NULL
bin: data field
b_lengthin: data field length, not UNIV_SQL_NULL
srsin: SRS of R-tree

◆ cmp_rec_rec_simple()

int cmp_rec_rec_simple ( const rec_t rec1,
const rec_t rec2,
const ulint offsets1,
const ulint offsets2,
const dict_index_t index,
struct TABLE table 
)

Compare two physical records that contain the same number of columns, none of which are stored externally.

Parameters
[in]rec1Physical record 1 to compare
[in]rec2Physical record 2 to compare
[in]offsets1rec_get_offsets(rec1, ...)
[in]offsets2rec_get_offsets(rec2, ...)
[in]indexData dictionary index
[in]tableMySQL table, for reporting duplicate key value if applicable, or nullptr
Return values
positiveif rec1 (including non-ordering columns) is greater than rec2
negativeif rec1 (including non-ordering columns) is less than rec2
0if rec1 is a duplicate of rec2

◆ cmp_rec_rec_simple_field()

static int cmp_rec_rec_simple_field ( const rec_t rec1,
const rec_t rec2,
const ulint offsets1,
const ulint offsets2,
const dict_index_t index,
ulint  n 
)
static

Compare two physical record fields.

Parameters
[in]rec1Physical record.
[in]rec2Physical record.
[in]offsets1rec_get_offsets(rec1, ...).
[in]offsets2rec_get_offsets(rec2, ...).
[in]indexData dictionary index.
[in]nField to compare.
Return values
positiveif rec1 field is greater than rec2
negativeif rec1 field is less than rec2
0if rec1 field equals to rec2

◆ cmp_rec_rec_with_match()

int cmp_rec_rec_with_match ( const rec_t rec1,
const rec_t rec2,
const ulint offsets1,
const ulint offsets2,
const dict_index_t index,
bool  spatial_index_non_leaf,
bool  nulls_unequal,
ulint matched_fields,
bool  cmp_btree_recs = true 
)

Compare two B-tree records.

Parameters
[in]rec1B-tree record
[in]rec2B-tree record
[in]offsets1rec_get_offsets(rec1, index)
[in]offsets2rec_get_offsets(rec2, index)
[in]indexB-tree index
[in]spatial_index_non_leaftrue if record is in spatial non leaf page
[in]nulls_unequaltrue if this is for index cardinality statistics estimation, and innodb_stats_method=nulls_unequal or innodb_stats_method=nulls_ignored
[out]matched_fieldsnumber of completely matched fields within the first field not completely matched
[in]cmp_btree_recstrue if we're comparing two b-tree records
Returns
the comparison result
Return values
0if rec1 is equal to rec2
negativeif rec1 is less than rec2
positiveif rec2 is greater than rec2

◆ cmp_whole_field()

static int cmp_whole_field ( ulint  mtype,
ulint  prtype,
bool  is_asc,
const byte a,
unsigned int  a_length,
const byte b,
unsigned int  b_length 
)
static

Compare two data fields.

Parameters
[in]mtypemain type
[in]prtypeprecise type
[in]is_asctrue=ascending, false=descending order
[in]adata field
[in]a_lengthlength of a, in bytes (not UNIV_SQL_NULL)
[in]bdata field
[in]b_lengthlength of b, in bytes (not UNIV_SQL_NULL)
Returns
positive, 0, negative, if a is greater, equal, less than b, respectively

◆ innobase_mysql_cmp()

static int innobase_mysql_cmp ( ulint  prtype,
const byte a,
size_t  a_length,
const byte b,
size_t  b_length 
)
inlinestatic

Compare two data fields.

Parameters
[in]prtypeprecise type
[in]adata field
[in]a_lengthlength of a, in bytes (not UNIV_SQL_NULL)
[in]bdata field
[in]b_lengthlength of b, in bytes (not UNIV_SQL_NULL)
Returns
positive, 0, negative, if a is greater, equal, less than b, respectively