diff --git a/src/box/field_def.c b/src/box/field_def.c index 672949e7e73649197e55d838da3811699e75bbb4..0d41d69042f588adb6674e50a621f956d425095d 100644 --- a/src/box/field_def.c +++ b/src/box/field_def.c @@ -201,7 +201,6 @@ static const struct opt_def field_def_reg[] = { OPT_DEF_ENUM("nullable_action", on_conflict_action, struct field_def, nullable_action, NULL), OPT_DEF("collation", OPT_UINT32, struct field_def, coll_id), - OPT_DEF("sql_default", OPT_STRPTR, struct field_def, sql_default_value), OPT_DEF_ENUM("compression", compression_type, struct field_def, compression_type, NULL), OPT_DEF_CUSTOM("default", field_def_parse_default_value), @@ -222,7 +221,6 @@ const struct field_def field_def_default = { .is_nullable = false, .nullable_action = ON_CONFLICT_ACTION_DEFAULT, .coll_id = COLL_NONE, - .sql_default_value = NULL, .default_value = NULL, .default_value_size = 0, .default_func_id = 0, @@ -443,10 +441,6 @@ field_def_array_dup(const struct field_def *fields, uint32_t field_count) grp_alloc_reserve_data(&all, sizeof(*fields) * field_count); for (uint32_t i = 0; i < field_count; i++) { grp_alloc_reserve_str0(&all, fields[i].name); - if (fields[i].sql_default_value != NULL) { - grp_alloc_reserve_str0(&all, - fields[i].sql_default_value); - } grp_alloc_reserve_data(&all, fields[i].default_value_size); } grp_alloc_use(&all, xmalloc(grp_alloc_size(&all))); @@ -455,10 +449,6 @@ field_def_array_dup(const struct field_def *fields, uint32_t field_count) for (uint32_t i = 0; i < field_count; ++i) { copy[i] = fields[i]; copy[i].name = grp_alloc_create_str0(&all, fields[i].name); - if (fields[i].sql_default_value != NULL) { - copy[i].sql_default_value = grp_alloc_create_str0( - &all, fields[i].sql_default_value); - } if (fields[i].default_value != NULL) { size_t size = fields[i].default_value_size; char *buf = grp_alloc_create_data(&all, size); diff --git a/src/box/field_def.h b/src/box/field_def.h index 0e69cc66b27a38ce41a1785ffba840fe019861bb..d1bcd2be293897974fb887404907c200b8b582f2 100644 --- a/src/box/field_def.h +++ b/src/box/field_def.h @@ -149,8 +149,6 @@ struct field_def { enum on_conflict_action nullable_action; /** Collation ID for string comparison. */ uint32_t coll_id; - /** 0-terminated SQL expression for DEFAULT value. */ - char *sql_default_value; /** MsgPack with the default value. */ char *default_value; /** Size of the default value. */ diff --git a/src/box/sql.c b/src/box/sql.c index 6ed98987fdbae32bbf132a9df83a24f3d2f9c789..fd8c489492452e31abdf8b863ef4236b46e33d82 100644 --- a/src/box/sql.c +++ b/src/box/sql.c @@ -66,18 +66,6 @@ static const char nil_key[] = { 0x90 }; /* Empty MsgPack array. */ static bool sql_seq_scan_default = false; TWEAK_BOOL(sql_seq_scan_default); -static Expr * -sql_expr_compile_cb(const char *expr, int expr_len) -{ - return sql_expr_compile(expr, expr_len); -} - -static void -sql_expr_delete_cb(struct Expr *expr) -{ - sql_expr_delete(expr); -} - uint32_t sql_default_session_flags(void) { @@ -89,9 +77,6 @@ sql_default_session_flags(void) void sql_init(void) { - tuple_format_expr_compile = sql_expr_compile_cb; - tuple_format_expr_delete = sql_expr_delete_cb; - current_session()->sql_flags = sql_default_session_flags(); if (sql_init_db(&db) != 0) @@ -365,7 +350,6 @@ sql_ephemeral_space_new(const struct sql_space_info *info) names += strlen(fields[i].name) + 1; fields[i].is_nullable = true; fields[i].nullable_action = ON_CONFLICT_ACTION_NONE; - fields[i].sql_default_value = NULL; fields[i].default_value = NULL; fields[i].default_value_size = 0; fields[i].default_func_id = 0; @@ -1012,12 +996,9 @@ sql_encode_table(struct region *region, struct space_def *def, uint32_t *size) for (uint32_t i = 0; i < field_count && !is_error; i++) { uint32_t cid = def->fields[i].coll_id; struct field_def *field = &def->fields[i]; - const char *default_str = field->sql_default_value; int base_len = 4; if (cid != COLL_NONE) base_len += 1; - if (default_str != NULL) - base_len += 1; if (field->default_value != NULL) base_len += 1; if (field->default_func_id != 0) @@ -1056,10 +1037,6 @@ sql_encode_table(struct region *region, struct space_def *def, uint32_t *size) mpstream_encode_str(&stream, "collation"); mpstream_encode_uint(&stream, cid); } - if (default_str != NULL) { - mpstream_encode_str(&stream, "sql_default"); - mpstream_encode_str(&stream, default_str); - } if (field->default_value != NULL) { mpstream_encode_str(&stream, "default"); mpstream_memcpy(&stream, field->default_value, diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c index 41e7e10243f119485ac267cab2225e59ddbd7d16..88748ff81264bac3b591a0bf34b920082f52e0b8 100644 --- a/src/box/sql/insert.c +++ b/src/box/sql/insert.c @@ -560,19 +560,11 @@ sqlInsert(Parse * pParse, /* Parser context */ } if ((!useTempTable && !pList) || (pColumn && j >= pColumn->nId)) { - if (i == (int) autoinc_fieldno) { - sqlVdbeAddOp2(v, OP_Integer, -1, - regCols + i + 1); - } else { - struct tuple_field *field = - tuple_format_field( - space->format, i); - struct Expr *dflt = - field->sql_default_value_expr; - sqlExprCode(pParse, - dflt, - regCols + i + 1); - } + int reg = regCols + i + 1; + if (i == (int)autoinc_fieldno) + sqlVdbeAddOp2(v, OP_Integer, -1, reg); + else + sqlVdbeAddOp2(v, OP_Null, 0, reg); } else if (useTempTable) { sqlVdbeAddOp3(v, OP_Column, srcTab, j, regCols + i + 1); @@ -624,17 +616,7 @@ sqlInsert(Parse * pParse, /* Parser context */ } if (j < 0 || nColumn == 0 || (pColumn && j >= pColumn->nId)) { - if (i == (int) autoinc_fieldno) { - sqlVdbeAddOp2(v, OP_Null, 0, iRegStore); - continue; - } - struct tuple_field *field = - tuple_format_field(space->format, i); - struct Expr *dflt = - field->sql_default_value_expr; - sqlExprCodeFactorable(pParse, - dflt, - iRegStore); + sqlVdbeAddOp2(v, OP_Null, 0, iRegStore); } else if (useTempTable) { if (i == (int) autoinc_fieldno) { int regTmp = ++pParse->nMem; @@ -1091,19 +1073,6 @@ xferOptimization(Parse * pParse, /* Parser context */ if (!dest->def->fields[i].is_nullable && src->def->fields[i].is_nullable) return 0; - /* Default values for second and subsequent columns need to match. */ - if (i > 0) { - char *src_expr_str = - src->def->fields[i].sql_default_value; - char *dest_expr_str = - dest->def->fields[i].sql_default_value; - if ((dest_expr_str == NULL) != (src_expr_str == NULL) || - (dest_expr_str && - strcmp(src_expr_str, dest_expr_str) != 0) - ) { - return 0; /* Default values must be the same for all columns */ - } - } } for (uint32_t i = 0; i < dest->index_count; ++i) { diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c index c3083fa2ea33e23a4dfd1b8b53ca5fcc5fb8db43..42ff1fa71b14d5276aa6310b457c96be54675395 100644 --- a/src/box/sql/pragma.c +++ b/src/box/sql/pragma.c @@ -113,10 +113,8 @@ sql_pragma_table_info(struct Parse *parse, const struct space *space) k = key_def_find_by_fieldno(kdef, i) - kdef->parts + 1; } sqlVdbeMultiLoad(v, 1, "issisi", i, field->name, - field_type_strs[field->type], - !field->is_nullable, - field->sql_default_value, - k); + field_type_strs[field->type], + !field->is_nullable, NULL, k); sqlVdbeAddOp2(v, OP_ResultRow, 1, 6); } } diff --git a/src/box/tuple_format.c b/src/box/tuple_format.c index a4095634daf1ad3008b2e79bed83f6ac9ccdecd5..5369293ac76f585169a3e009b8251589a444900d 100644 --- a/src/box/tuple_format.c +++ b/src/box/tuple_format.c @@ -49,9 +49,6 @@ static intptr_t recycled_format_ids = FORMAT_ID_NIL; static uint32_t formats_size = 0, formats_capacity = 0; static uint64_t formats_epoch = 0; -tuple_format_expr_compile_f tuple_format_expr_compile; -tuple_format_expr_delete_f tuple_format_expr_delete; - /** * Find in format1::fields the field by format2_field's JSON path. * Routine uses fiber region for temporal path allocation and @@ -118,21 +115,6 @@ tuple_format_cmp(const struct tuple_format *format1, if (field_a->is_key_part != field_b->is_key_part) return (int)field_a->is_key_part - (int)field_b->is_key_part; - if (field_a->sql_default_value_expr != - field_b->sql_default_value_expr) { - /* - * We cannot compare SQL expression ASTs, so as a - * workaround we compare pointers (which are actually - * never equal): since we need to provide some total - * order, we compare pointer values. - */ - uintptr_t ptr_a = - (uintptr_t)field_a->sql_default_value_expr; - uintptr_t ptr_b = - (uintptr_t)field_b->sql_default_value_expr; - intptr_t cmp = (intptr_t)(ptr_a - ptr_b); - return cmp < 0 ? -1 : 1; - } if (field_a->compression_type != field_b->compression_type) return (int)field_a->compression_type - (int)field_b->compression_type; @@ -184,8 +166,6 @@ tuple_format_hash(struct tuple_format *format) TUPLE_FIELD_MEMBER_HASH(f, coll_id, h, carry, size) TUPLE_FIELD_MEMBER_HASH(f, nullable_action, h, carry, size) TUPLE_FIELD_MEMBER_HASH(f, is_key_part, h, carry, size) - TUPLE_FIELD_MEMBER_HASH(f, sql_default_value_expr, h, carry, - size) TUPLE_FIELD_MEMBER_HASH(f, compression_type, h, carry, size); for (uint32_t i = 0; i < f->constraint_count; ++i) size += tuple_constraint_hash_process(&f->constraint[i], @@ -241,8 +221,6 @@ tuple_field_delete(struct tuple_field *field) for (uint32_t i = 0; i < field->constraint_count; i++) field->constraint[i].destroy(&field->constraint[i]); free(field->constraint); - if (field->sql_default_value_expr != NULL) - tuple_format_expr_delete(field->sql_default_value_expr); field_default_func_destroy(&field->default_value.func); free(field->default_value.data); free(field); @@ -555,13 +533,6 @@ tuple_format_create(struct tuple_format *format, struct key_def *const *keys, tuple_constraint_array_new(fields[i].constraint_def, fields[i].constraint_count); field->constraint_count = fields[i].constraint_count; - const char *expr = fields[i].sql_default_value; - if (expr != NULL) { - field->sql_default_value_expr = - tuple_format_expr_compile(expr, strlen(expr)); - if (field->sql_default_value_expr == NULL) - return -1; - } if (fields[i].default_func_id > 0) { field->default_value.func.id = fields[i].default_func_id; diff --git a/src/box/tuple_format.h b/src/box/tuple_format.h index d261e06e1b39ca4a54947ede9c51f9316df11c46..d691d1af772389f2ec715b5a86363cea40531d51 100644 --- a/src/box/tuple_format.h +++ b/src/box/tuple_format.h @@ -69,27 +69,8 @@ struct tuple; struct tuple_info; struct tuple_format; struct coll; -struct Expr; struct mpstream; -typedef struct Expr * -(*tuple_format_expr_compile_f)(const char *expr, int expr_len); - -typedef void -(*tuple_format_expr_delete_f)(struct Expr *expr); - -/** - * Callback that compiles an SQL expression. - * Needed for avoid SQL dependency. - */ -extern tuple_format_expr_compile_f tuple_format_expr_compile; - -/** - * Callback that deletes an SQL expression. - * Needed for avoid SQL dependency. - */ -extern tuple_format_expr_delete_f tuple_format_expr_delete; - /** Engine-specific tuple format methods. */ struct tuple_format_vtab { /** @@ -183,8 +164,6 @@ struct tuple_field { struct tuple_constraint *constraint; /** Number of constraints. */ uint32_t constraint_count; - /** AST for parsed SQL default value. */ - struct Expr *sql_default_value_expr; /** Tuple field default value. */ struct field_default_value default_value; }; diff --git a/test/unit/tuple_format.c b/test/unit/tuple_format.c index 8bdf8984f6a2b7db73543abfb16e0bd54e596c7e..08eaff3600911187a74654dde63d767d4456047f 100644 --- a/test/unit/tuple_format.c +++ b/test/unit/tuple_format.c @@ -31,7 +31,7 @@ mpstream_error(void *is_err) static int test_tuple_format_cmp(void) { - plan(19); + plan(18); header(); char buf[1024]; @@ -124,17 +124,6 @@ test_tuple_format_cmp(void) coll_id_delete(coll_id2); coll_id_delete(coll_id1); - size = mp_format(buf, lengthof(buf), "[{%s%s %s%s}]", - "name", "f", "sql_default", "1 + 1"); - f1 = runtime_tuple_format_new(buf, size, false); - size = mp_format(buf, lengthof(buf), "[{%s%s %s%s}]", - "name", "f", "sql_default", "2"); - f2 = runtime_tuple_format_new(buf, size, false); - ok(f1 != f2, "tuple formats with different expressions in " - "'sql_default' definitions are not equal"); - tuple_format_delete(f1); - tuple_format_delete(f2); - size = mp_format(buf, lengthof(buf), "[{%s%s %s{%s%d %s%d}}]", "name", "f", "constraint", "c1", 1, "c2", 2);