Skip to content

Commit e020a74

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

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

db/tag.c

+17-1
Original file line numberDiff line numberDiff line change
@@ -6522,17 +6522,33 @@ int create_key_from_ireq(struct ireq *iq, int ixnum, int isDelete, char **tail,
65226522
// autoinc value is not set on replicant, set it now
65236523
struct schema *idx_schema = get_schema(db, ixnum);
65246524
struct schema *schema = get_schema(db, -1);
6525+
int rec_srt_off = gbl_sort_nulls_correctly ? 0 : 1;
6526+
char temp[9];
6527+
char *check_for_resolve_master;
65256528
for (int nfield = 0; nfield < idx_schema->nmembers; nfield++) {
65266529
const struct field *idx_field = &idx_schema->member[nfield];
65276530
// TODO: expression idx
65286531
if (idx_field->isExpr)
65296532
continue;
6530-
if (!(idx_field->in_default_type == SERVER_SEQUENCE && stype_is_resolve_master(outbuf + idx_field->offset)))
6533+
if (idx_field->in_default_type != SERVER_SEQUENCE)
6534+
continue;
6535+
6536+
if (idx_field->flags & INDEX_DESCEND) { // need to undo to check for resolve master bit
6537+
assert(idx_field->len <= sizeof(temp));
6538+
memcpy(temp, outbuf + idx_field->offset, idx_field->len);
6539+
xorbuf(temp + rec_srt_off, idx_field->len - rec_srt_off);
6540+
check_for_resolve_master = temp;
6541+
} else
6542+
check_for_resolve_master = outbuf + idx_field->offset;
6543+
6544+
if (!stype_is_resolve_master(check_for_resolve_master))
65316545
continue;
65326546
// grab actual autoinc value from the record
65336547
const struct field *field = &schema->member[idx_field->idx];
65346548
assert(idx_field->len == field->len);
65356549
memcpy(outbuf + idx_field->offset, inbuf + field->offset, idx_field->len);
6550+
if (idx_field->flags & INDEX_DESCEND)
6551+
xorbuf((outbuf + idx_field->offset) + rec_srt_off, idx_field->len - rec_srt_off);
65366552
}
65376553

65386554
if (db->ix_datacopy[ixnum]) {

tests/nextsequence.test/runit

+13-12
Original file line numberDiff line numberDiff line change
@@ -466,23 +466,23 @@ function insert_with_idx_and_dummy_expr
466466
{
467467
disable_strict_mode
468468
$CDB2SQL_EXE $CDB2_OPTIONS $DBNAME default - <<EOF
469-
create table seqwithidxanddummyexpr {$(cat seqwithidxanddummyexpr.csc2)}\$\$
469+
create table $1 {$(cat $1.csc2)}\$\$
470470
EOF
471471

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"
472+
$CDB2SQL_EXE $CDB2_OPTIONS $DBNAME default "insert into $1(a) values(1)"
473+
[[ $? != 0 ]] && failexit "$1 table should have been allowed to insert"
474+
$CDB2SQL_EXE $CDB2_OPTIONS $DBNAME default "insert into $1 values(2, 2)"
475+
[[ $? != 0 ]] && failexit "$1 table should have been allowed to insert"
476+
$CDB2SQL_EXE $CDB2_OPTIONS $DBNAME default "insert into $1 values(NULL, NULL)"
477+
[[ $? != 0 ]] && failexit "$1 table should have been allowed to insert"
478478

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"
479+
out=$($CDB2SQL_EXE $CDB2_OPTIONS $DBNAME default "select b from $1 order by b")
480+
[[ $? != 0 ]] && failexit "$1 table should have been allowed to select"
481481
exp=$'(b=NULL)\n(b=1)\n(b=2)'
482482
[[ $out != $exp ]] && failexit "Got $out, Expected $exp"
483483

484-
$CDB2SQL_EXE -tabs $CDB2_OPTIONS $DBNAME default "exec procedure sys.cmd.verify('seqwithidxanddummyexpr')"
485-
[[ $? != 0 ]] && failexit "seqwithidxanddummyexpr should have passed verify"
484+
$CDB2SQL_EXE -tabs $CDB2_OPTIONS $DBNAME default "exec procedure sys.cmd.verify('$1')"
485+
[[ $? != 0 ]] && failexit "$1 should have passed verify"
486486
}
487487

488488
function run_test
@@ -515,7 +515,8 @@ function run_test
515515
lrl_sequence
516516
fi
517517

518-
insert_with_idx_and_dummy_expr
518+
insert_with_idx_and_dummy_expr seqwithidxanddummyexpr
519+
insert_with_idx_and_dummy_expr seqwithdescidxanddummyexpr
519520
}
520521

521522
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" = <DESCEND>b
9+
dup "expr" = (int)"1 + 1"
10+
}

0 commit comments

Comments
 (0)