* This file is part of the oGRAC project.
* Copyright (c) 2024 Huawei Technologies Co.,Ltd.
*
* oGRAC is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* -------------------------------------------------------------------------
*
* dml_defs.h
*
*
* IDENTIFICATION
* src/kernel/include/dml_defs.h
*
* -------------------------------------------------------------------------
*/
#ifndef __KNL_DML_DEFS_H__
#define __KNL_DML_DEFS_H__
#include "knl_defs.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct st_knl_column {
uint32 id;
char *name;
uint32 uid;
uint32 table_id;
uint32 datatype;
uint32 size;
int32 precision;
int32 scale;
bool32 nullable;
uint32 flags;
text_t default_text;
void *lob;
void *default_expr;
void *ddm_expr;
void *update_default_expr;
uint32 next;
latch_t cbo_col_latch;
} knl_column_t;
typedef enum st_nologing_type {
LOGGING_LEVEL = 0,
SESSION_LEVEL = 1,
TABLE_LEVEL = 2,
} nologing_type_t;
#define KNL_COLUMN_FLAG_HIDDEN 0x00000001
#define KNL_COLUMN_FLAG_DELETED 0x00000002
#define KNL_COLUMN_FLAG_COMPRESSED 0x00000004
#define KNL_COLUMN_FLAG_SERIAL 0x00000008
#define KNL_COLUMN_FLAG_UPDATE_DEFAULT 0x00000010
#define KNL_COLUMN_FLAG_CHARACTER 0x00000020
#define KNL_COLUMN_FLAG_VIRTUAL 0x00000040
#define KNL_COLUMN_FLAG_DESCEND 0x00000080
#define KNL_COLUMN_FLAG_QUOTE 0x00000100
#define KNL_COLUMN_FLAG_DEFAULT_NULL 0x00000200
#define KNL_COLUMN_FLAG_ARRAY 0x00000400
#define KNL_COLUMN_FLAG_JSONB 0x00000800
#define KNL_COLUMN_FLAG_ROWID_TYPE 0x00001000
#define KNL_COLUMN_INVISIBLE(col) \
((col)->flags & (KNL_COLUMN_FLAG_HIDDEN | KNL_COLUMN_FLAG_DELETED | KNL_COLUMN_FLAG_VIRTUAL))
#define KNL_COLUMN_IS_DELETED(col) (((col)->flags & KNL_COLUMN_FLAG_DELETED) != 0)
#define KNL_COLUMN_IS_HIDDEN(col) (((col)->flags & KNL_COLUMN_FLAG_HIDDEN) != 0)
#define KNL_COLUMN_IS_UPDATE_DEFAULT(col) (((col)->flags & KNL_COLUMN_FLAG_UPDATE_DEFAULT) != 0)
#define KNL_COLUMN_IS_CHARACTER(col) (((col)->flags & KNL_COLUMN_FLAG_CHARACTER) != 0)
#define KNL_COLUMN_IS_SERIAL(col) (((col)->flags & KNL_COLUMN_FLAG_SERIAL) != 0)
#define KNL_COLUMN_HAS_QUOTE(col) (((col)->flags & KNL_COLUMN_FLAG_QUOTE) != 0)
#define KNL_COLUMN_IS_VIRTUAL(col) (((col)->flags & KNL_COLUMN_FLAG_VIRTUAL) != 0)
#define KNL_COLUMN_IS_DESCEND(col) (((col)->flags & KNL_COLUMN_FLAG_DESCEND) != 0)
#define KNL_COLUMN_IS_DEFAULT_NULL(col) (((col)->flags & KNL_COLUMN_FLAG_DEFAULT_NULL) != 0)
#define KNL_COLUMN_IS_ARRAY(col) (((col)->flags & KNL_COLUMN_FLAG_ARRAY) != 0)
#define KNL_COLUMN_IS_JSONB(col) (((col)->flags & KNL_COLUMN_FLAG_JSONB) != 0)
#define KNL_COLUMN_IS_ROWID_TYPE(col) (((col)->flags & KNL_COLUMN_FLAG_ROWID_TYPE) != 0)
typedef enum st_rowmark_type {
ROWMARK_WAIT_BLOCK = 0,
ROWMARK_WAIT_SECOND,
ROWMARK_NOWAIT,
ROWMARK_SKIP_LOCKED
} rowmark_type_t;
typedef union st_rowmark {
uint64 value;
struct {
rowmark_type_t type;
uint32 wait_seconds;
};
} rowmark_t;
typedef enum en_knl_scan_mode {
SCAN_MODE_TABLE_FULL = 1,
SCAN_MODE_ROWID = 2,
SCAN_MODE_INDEX = 3,
} knl_scan_mode_t;
typedef enum en_knl_cursor_action {
CURSOR_ACTION_FOR_UPDATE_SCAN = 1,
CURSOR_ACTION_SELECT = 2,
CURSOR_ACTION_UPDATE = 3,
CURSOR_ACTION_INSERT = 4,
CURSOR_ACTION_DELETE = 5,
} knl_cursor_action_t;
#define SCAN_KEY_NORMAL 0
#define SCAN_KEY_LEFT_INFINITE 1
#define SCAN_KEY_RIGHT_INFINITE 2
#define SCAN_KEY_MINIMAL 3
#define SCAN_KEY_MAXIMAL 4
#define SCAN_KEY_IS_NULL 5
typedef struct st_knl_scan_key_t {
uint8 flags[OG_MAX_INDEX_COLUMNS];
uint16 offsets[OG_MAX_INDEX_COLUMNS];
char *buf;
} knl_scan_key_t;
typedef struct st_knl_scan_range {
union {
struct {
char l_buf[OG_KEY_BUF_SIZE];
char r_buf[OG_KEY_BUF_SIZE];
char org_buf[OG_KEY_BUF_SIZE];
knl_scan_key_t l_key;
knl_scan_key_t r_key;
knl_scan_key_t org_key;
bool32 is_equal;
};
struct {
page_id_t l_page;
page_id_t r_page;
};
};
} knl_scan_range_t;
typedef struct st_knl_update_info {
uint16 count;
char *data;
uint16 *columns;
uint16 *offsets;
uint16 *lens;
} knl_update_info_t;
typedef struct st_key_locator {
knl_scn_t seg_scn;
uint64 lsn;
page_id_t page_id;
page_id_t next_page_id;
page_id_t prev_page_id;
knl_scn_t pid_snap_scn;
knl_scn_t next_pid_snap_scn;
uint64 index_ver;
uint16 slot;
uint16 slot_end;
uint32 pcn;
uint8 is_located;
uint8 is_last_key;
uint8 page_cache;
bool8 is_initialized;
bool8 match_left;
bool8 match_right;
bool8 cmp_end;
uint8 equal_cols;
bool8 skip_cache;
uint8 aligned[7];
} key_locator_t;
typedef struct st_undo_snapshot {
knl_scn_t scn;
undo_page_id_t undo_page;
uint64 xid;
uint16 undo_slot;
uint16 is_xfirst : 1;
uint16 is_owscn : 1;
uint16 is_valid : 1;
uint16 contain_subpartno : 1;
uint16 unused : 12;
} undo_snapshot_t;
#define KNL_ROWID_LEN sizeof(rowid_t)
#define REMOTE_ROWNODEID_LEN sizeof(uint16)
#define KNL_ROWID_ARRAY_SIZE (uint32)(OG_ROWID_BUF_SIZE / KNL_ROWID_LEN)
typedef struct st_knl_cursor knl_cursor_t;
typedef status_t (*knl_cursor_operator_t)(knl_handle_t session, knl_cursor_t *cursor);
typedef status_t (*knl_cursor_operator1_t)(knl_handle_t session, knl_cursor_t *cursor, bool32 *is_found);
typedef struct st_knl_part_locate {
uint32 part_no;
uint32 subpart_no;
} knl_part_locate_t;
typedef struct st_knl_parts_locate {
knl_part_locate_t part[MAX_REBUILD_PARTS];
uint32 specified_parts;
} knl_parts_locate_t;
static const knl_part_locate_t g_invalid_part_loc = { .part_no = OG_INVALID_ID32, .subpart_no = OG_INVALID_ID32 };
* struct used for init cursor
* @note must be consistent with variable in cursor,
* variable which needs to be init during init cursor must
* be copied here in the same position
*/
typedef struct st_init_cursor {
void *stmt;
knl_handle_t temp_cache;
vm_page_t *vm_page;
int32 file;
knl_part_locate_t part_loc;
uint16 rowid_count;
uint16 decode_count;
uint8 chain_count;
uint8 index_slot;
bool8 index_dsc : 1;
bool8 index_only : 1;
bool8 index_ffs : 1;
bool8 index_ss : 1;
bool8 index_paral : 1;
bool8 index_prefetch_row : 1;
bool8 skip_index_match : 1;
bool8 asc_relocate_next_key : 1;
bool8 set_default;
bool8 restrict_part;
bool8 restrict_subpart;
bool8 is_valid;
bool8 eof;
bool8 logging : 1;
bool8 page_soft_damaged : 1;
bool8 res_flag : 6;
bool8 global_cached;
rowmark_t rowmark;
bool8 is_splitting;
bool8 for_update_fetch;
nologing_type_t nologging_type;
} init_cursor_t;
typedef struct st_json_step_loc {
uint32 pair_idx;
uint32 pair_offset;
} json_step_loc_t;
typedef struct st_json_table_exec {
bool8 table_ready;
bool8 end;
bool8 last_extend;
bool8 exists;
uint64 ordinality;
json_step_loc_t *loc;
struct st_json_path *basic_path;
pointer_t json_value;
pointer_t json_assist;
} json_table_exec_t;
typedef struct st_knl_cursor {
union {
struct {
void *stmt;
knl_handle_t temp_cache;
vm_page_t *vm_page;
int32 file;
knl_part_locate_t part_loc;
uint16 rowid_count;
uint16 decode_count;
uint8 chain_count;
uint8 index_slot;
union {
struct {
bool8 index_dsc : 1;
bool8 index_only : 1;
bool8 index_ffs : 1;
bool8 index_ss : 1;
bool8 index_paral : 1;
bool8 index_prefetch_row : 1;
bool8 skip_index_match : 1;
bool8 asc_relocate_next_key : 1;
};
uint8 index_flag;
};
bool8 set_default;
bool8 restrict_part;
bool8 restrict_subpart;
bool8 is_valid;
bool8 eof;
bool8 logging : 1;
bool8 page_soft_damaged : 1;
bool8 res_flag : 6;
bool8 global_cached;
rowmark_t rowmark;
bool8 is_splitting;
bool8 for_update_fetch;
nologing_type_t nologging_type;
};
init_cursor_t init_cursor;
};
knl_scan_mode_t scan_mode;
knl_cursor_action_t action;
knl_scan_range_t scan_range;
knl_update_info_t update_info;
knl_update_info_t insert_info;
uint16 decode_cln_total;
uint16 *offsets;
uint16 *lens;
uint16 lob_inline_num;
uint16 data_size;
knl_dict_type_t dc_type;
knl_handle_t dc_entity;
knl_handle_t table;
knl_handle_t table_part;
knl_handle_t index;
knl_handle_t index_part;
char *vnc_column;
int32 fd;
text_t text;
char key[OG_KEY_BUF_SIZE];
rowid_t rowid_array[KNL_ROWID_ARRAY_SIZE];
key_locator_t key_loc;
uint16 bitmap;
bool8 disable_pk_update;
knl_scn_t scn;
knl_scn_t query_scn;
uint64 query_lsn;
uint64 xid;
uint64 reused_xid;
uint64 ssn;
rowid_t rowid;
rowid_t link_rid;
rowid_t conflict_rid;
rowid_t rowid_pos;
undo_snapshot_t snapshot;
char *chain_info;
row_head_t *row;
char *page_buf;
uint16 rowid_no;
uint16 row_offset;
bool8 is_locked;
bool8 ssi_conflict;
uint8 isolevel;
bool8 cleanout;
bool8 is_xfirst;
bool8 page_cache;
bool32 is_found;
date_t cc_cache_time;
uint32 tenant_id;
knl_cursor_operator_t fetch;
bool8 skip_lock;
uint8 conflict_idx_slot;
bool8 is_cascade;
bool8 is_create_select;
char buf[0];
} knl_cursor_t;
* Kernel support row level consistent read mode and page level consistent read mode
*/
typedef enum st_cr_mode {
CR_ROW = 0,
CR_PAGE = 1,
} cr_mode_t;
* Kernel support row format setting, it is a default value.
*/
typedef enum st_row_format {
ROW_FORMAT_ASF = 0,
ROW_FORMAT_CSF = 1,
} row_format_t;
* btree interface
*/
typedef struct st_knl_icol_info {
bool32 is_func;
og_type_t datatype;
uint32 size;
bool32 is_dsc;
uint16 arg_count;
uint16 *arg_cols;
} knl_icol_info_t;
#define KNL_INDEX_FLAG_INVALID 0x00000004
#define KNL_INDEX_FLAG_IS_INVALID(index_flags) (((index_flags) & KNL_INDEX_FLAG_INVALID) != 0)
typedef struct st_index_profile {
uint32 table_id;
uint16 uid;
uint8 index_id;
bool8 is_shadow;
bool32 primary;
bool32 unique;
bool32 global_idx_for_part_table;
bool32 is_compart_table;
uint32 column_count;
og_type_t types[OG_MAX_INDEX_COLUMNS];
} index_profile_t;
typedef struct st_knl_index_desc {
uint32 slot;
uint32 id;
uint32 uid;
uint32 space_id;
uint32 table_id;
char name[OG_NAME_BUFFER_SIZE];
knl_scn_t org_scn;
knl_scn_t seg_scn;
page_id_t entry;
bool32 primary;
bool32 unique;
index_type_t type;
uint32 column_count;
uint16 columns[OG_MAX_INDEX_COLUMNS];
uint32 initrans;
cr_mode_t cr_mode;
union {
uint32 flags;
struct {
uint32 is_cons : 1;
uint32 is_disabled : 1;
uint32 is_invalid : 1;
uint32 is_stored : 1;
uint32 is_encode : 1;
uint32 is_func : 1;
uint32 is_reverse : 1;
uint32 is_nologging : 1;
uint32 unused_flag : 24;
};
};
uint32 parted;
uint32 pctfree;
bool32 is_enforced;
knl_icol_info_t *columns_info;
uint16 max_key_size;
uint8 maxtrans;
bool8 part_idx_invalid;
bool8 is_dsc;
index_profile_t profile;
uint8 col_dirs[OG_MAX_INDEX_COLUMNS];
} knl_index_desc_t;
void knl_init_key(knl_index_desc_t *desc, char *buf, rowid_t *rid);
void knl_set_key_rowid(knl_index_desc_t *desc, char *buf, rowid_t *rid);
void knl_put_key_data(knl_index_desc_t *desc, char *buf, og_type_t type, const void *data, uint16 len, uint16 id);
uint32 knl_get_key_size(knl_index_desc_t *desc, const char *buf);
void knl_set_key_size(knl_index_desc_t *desc, knl_scan_key_t *key, uint32 size);
uint32 knl_scan_key_size(knl_index_desc_t *desc, knl_scan_key_t *key);
void knl_init_index_scan(knl_cursor_t *cursor, bool32 is_equal);
void knl_set_scan_key(knl_index_desc_t *desc, knl_scan_key_t *scan_key, og_type_t type, const void *data, uint16 len,
uint16 id);
void knl_set_key_flag(knl_scan_key_t *border, uint8 flag, uint16 id);
status_t knl_get_table_of_index(knl_handle_t se, text_t *user, text_t *index, text_t *table);
void knl_get_index_name(knl_index_desc_t *desc, char *name, uint32 max_len);
status_t knl_insert(knl_handle_t session, knl_cursor_t *cursor);
status_t knl_internal_insert(knl_handle_t session, knl_cursor_t *cursor);
status_t knl_insert_indexes(knl_handle_t handle, knl_cursor_t *cursor);
status_t knl_delete(knl_handle_t session, knl_cursor_t *cursor);
status_t knl_internal_delete(knl_handle_t handle, knl_cursor_t *cursor);
status_t knl_update(knl_handle_t session, knl_cursor_t *cursor);
status_t knl_internal_update(knl_handle_t session, knl_cursor_t *cursor);
status_t knl_crosspart_update(knl_handle_t se, knl_cursor_t *cursor, knl_part_locate_t new_part_loc);
status_t knl_fetch(knl_handle_t session, knl_cursor_t *cursor);
status_t knl_fetch_by_rowid(knl_handle_t session, knl_cursor_t *cursor, bool32 *is_found);
status_t knl_copy_row(knl_handle_t handle, knl_cursor_t *src, knl_cursor_t *dest);
status_t knl_lock_row(knl_handle_t session, knl_cursor_t *cursor, bool32 *is_found);
status_t knl_verify_children_dependency(knl_handle_t session, knl_cursor_t *cursor, bool32 is_update,
uint8 depth, bool32 is_dd_table);
status_t knl_verify_ref_integrities(knl_handle_t session, knl_cursor_t *cursor);
knl_column_t *knl_find_column(text_t *col_name, knl_dictionary_t *dc);
knl_column_t *knl_get_column(knl_handle_t dc_entity, uint32 id);
typedef struct st_knl_paral_range {
uint32 workers;
page_id_t l_page[OG_MAX_PARAL_QUERY];
page_id_t r_page[OG_MAX_PARAL_QUERY];
} knl_paral_range_t;
status_t knl_get_paral_schedule(knl_handle_t handle, knl_dictionary_t *dc, knl_part_locate_t part_loc, uint32 workers,
knl_paral_range_t *range);
uint16 knl_get_column_id(knl_dictionary_t *dc, text_t *name);
uint32 knl_get_column_count(knl_handle_t dc_entity);
#ifdef __cplusplus
}
#endif
#endif