Skip to content

Commit

Permalink
Fix a bug that deleting record can be found
Browse files Browse the repository at this point in the history
If a record has fixed size column (e.g. Int32) and it is indexed, the
bug is occurred. If a record is deleted, the deleted record can be
found index search with 0 value. 0 value for Int32 is 0.

This fixes mroonga's bug found at
c2b8afce57c89286f8118ebcc5e6260c902c2488.
  • Loading branch information
kou committed Nov 16, 2012
1 parent 4958270 commit a9f3918
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 3 deletions.
3 changes: 0 additions & 3 deletions lib/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -1528,10 +1528,7 @@ grn_obj_clear_value(grn_ctx *ctx, grn_obj *obj, grn_id id)
GRN_OBJ_INIT(&buf, GRN_BULK, 0, range);
switch (obj->header.type) {
case GRN_COLUMN_VAR_SIZE :
rc = grn_obj_set_value(ctx, obj, id, &buf, GRN_OBJ_SET);
break;
case GRN_COLUMN_FIX_SIZE :
grn_bulk_truncate(ctx, &buf, ((grn_ra *)obj)->header->element_size);
rc = grn_obj_set_value(ctx, obj, id, &buf, GRN_OBJ_SET);
break;
}
Expand Down
134 changes: 134 additions & 0 deletions test/command/suite/delete/index/fix_size_column.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
table_create Users TABLE_HASH_KEY ShortText
[[0,0.0,0.0],true]
column_create Users age COLUMN_SCALAR UInt8
[[0,0.0,0.0],true]
table_create Ages TABLE_PAT_KEY UInt8
[[0,0.0,0.0],true]
column_create Ages users_age COLUMN_INDEX Users age
[[0,0.0,0.0],true]
load --table Users
[
{"_key": "Alice", "age": 20},
{"_key": "Bob", "age": 18}
]
[[0,0.0,0.0],2]
select Ages
[
[
0,
0.0,
0.0
],
[
[
[
2
],
[
[
"_id",
"UInt32"
],
[
"_key",
"UInt8"
],
[
"users_age",
"Users"
]
],
[
2,
18,
1
],
[
1,
20,
1
]
]
]
]
select Users --filter 'age == 20'
[
[
0,
0.0,
0.0
],
[
[
[
1
],
[
[
"_id",
"UInt32"
],
[
"_key",
"ShortText"
],
[
"age",
"UInt8"
]
],
[
1,
"Alice",
20
]
]
]
]
select Users --filter 'age == 0'
[[0,0.0,0.0],[[[0],[["_id","UInt32"],["_key","ShortText"],["age","UInt8"]]]]]
delete Users --filter 'age == 20'
[[0,0.0,0.0],true]
select Ages
[
[
0,
0.0,
0.0
],
[
[
[
2
],
[
[
"_id",
"UInt32"
],
[
"_key",
"UInt8"
],
[
"users_age",
"Users"
]
],
[
2,
18,
1
],
[
1,
20,
0
]
]
]
]
select Users --filter 'age == 20'
[[0,0.0,0.0],[[[0],[["_id","UInt32"],["_key","ShortText"],["age","UInt8"]]]]]
select Users --filter 'age == 0'
[[0,0.0,0.0],[[[0],[["_id","UInt32"],["_key","ShortText"],["age","UInt8"]]]]]
21 changes: 21 additions & 0 deletions test/command/suite/delete/index/fix_size_column.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
table_create Users TABLE_HASH_KEY ShortText
column_create Users age COLUMN_SCALAR UInt8

table_create Ages TABLE_PAT_KEY UInt8
column_create Ages users_age COLUMN_INDEX Users age

load --table Users
[
{"_key": "Alice", "age": 20},
{"_key": "Bob", "age": 18}
]

select Ages
select Users --filter 'age == 20'
select Users --filter 'age == 0'

delete Users --filter 'age == 20'

select Ages
select Users --filter 'age == 20'
select Users --filter 'age == 0'

0 comments on commit a9f3918

Please sign in to comment.