Skip to content

Commit c30cac2

Browse files
committed
{178575361} Fill autoinc value for ireq keys that are not expressions on master
Signed-off-by: Salil Chandra <[email protected]>
1 parent 94f96b9 commit c30cac2

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

db/tag.c

+17
Original file line numberDiff line numberDiff line change
@@ -2896,6 +2896,7 @@ int upd_master_columns(struct ireq *iq, void *intrans, void *record, size_t recl
28962896

28972897
int set_master_columns(struct ireq *iq, void *intrans, void *record, size_t reclen)
28982898
{
2899+
// also may need to add case to create_key_from_ireq
28992900
tran_type *tran = (tran_type *)intrans;
29002901
char *crec = record;
29012902
int rc = 0, bdberr = 0;
@@ -6518,6 +6519,22 @@ int create_key_from_ireq(struct ireq *iq, int ixnum, int isDelete, char **tail,
65186519
else
65196520
memcpy(outbuf, iq->idxInsert[ixnum], db->ix_keylen[ixnum]);
65206521

6522+
// autoinc value is not set on replicant, set it now
6523+
struct schema *idx_schema = get_schema(db, ixnum);
6524+
struct schema *schema = get_schema(db, -1);
6525+
for (int nfield = 0; nfield < idx_schema->nmembers; nfield++) {
6526+
const struct field *idx_field = &idx_schema->member[nfield];
6527+
// TODO: expression idx
6528+
if (idx_field->isExpr)
6529+
continue;
6530+
if (!(idx_field->in_default_type == SERVER_SEQUENCE && stype_is_resolve_master(outbuf + idx_field->offset)))
6531+
continue;
6532+
// grab actual autoinc value from the record
6533+
const struct field *field = &schema->member[idx_field->idx];
6534+
assert(idx_field->len == field->len);
6535+
memcpy(outbuf + idx_field->offset, inbuf + field->offset, idx_field->len);
6536+
}
6537+
65216538
if (db->ix_datacopy[ixnum]) {
65226539
assert(db->ix_collattr[ixnum] == 0);
65236540

tests/nextsequence.test/runit

+25
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,29 @@ function verify_and_fix_corruption
462462
echo "$x"
463463
}
464464

465+
function insert_with_idx_and_dummy_expr
466+
{
467+
disable_strict_mode
468+
$CDB2SQL_EXE $CDB2_OPTIONS $DBNAME default - <<EOF
469+
create table seqwithidxanddummyexpr {$(cat seqwithidxanddummyexpr.csc2)}\$\$
470+
EOF
471+
472+
$CDB2SQL_EXE $CDB2_OPTIONS $DBNAME default "insert into seqwithidxanddummyexpr(a) values(1)"
473+
[[ $? != 0 ]] && failexit "seqwithidxanddummyexpr table should have been allowed to insert"
474+
$CDB2SQL_EXE $CDB2_OPTIONS $DBNAME default "insert into seqwithidxanddummyexpr values(2, 2)"
475+
[[ $? != 0 ]] && failexit "seqwithidxanddummyexpr table should have been allowed to insert"
476+
$CDB2SQL_EXE $CDB2_OPTIONS $DBNAME default "insert into seqwithidxanddummyexpr values(NULL, NULL)"
477+
[[ $? != 0 ]] && failexit "seqwithidxanddummyexpr table should have been allowed to insert"
478+
479+
out=$($CDB2SQL_EXE $CDB2_OPTIONS $DBNAME default "select b from seqwithidxanddummyexpr order by b")
480+
[[ $? != 0 ]] && failexit "seqwithidxanddummyexpr table should have been allowed to select"
481+
exp=$'(b=NULL)\n(b=1)\n(b=2)'
482+
[[ $out != $exp ]] && failexit "Got $out, Expected $exp"
483+
484+
$CDB2SQL_EXE -tabs $CDB2_OPTIONS $DBNAME default "exec procedure sys.cmd.verify('seqwithidxanddummyexpr')"
485+
[[ $? != 0 ]] && failexit "seqwithidxanddummyexpr should have passed verify"
486+
}
487+
465488
function run_test
466489
{
467490
set_output_files
@@ -491,6 +514,8 @@ function run_test
491514
else
492515
lrl_sequence
493516
fi
517+
518+
insert_with_idx_and_dummy_expr
494519
}
495520

496521
run_test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
schema
2+
{
3+
int a null=yes
4+
int b dbstore=nextsequence null=yes
5+
}
6+
keys
7+
{
8+
"b" = b
9+
dup "expr" = (int)"1 + 1"
10+
}

0 commit comments

Comments
 (0)