@@ -45,7 +45,7 @@ ART::ART(const string &name, const IndexConstraintType index_constraint_type, co
4545 const shared_ptr<array<unsafe_unique_ptr<FixedSizeAllocator>, ALLOCATOR_COUNT>> &allocators_ptr,
4646 const IndexStorageInfo &info)
4747 : BoundIndex(name, ART::TYPE_NAME, index_constraint_type, column_ids, table_io_manager, unbound_expressions, db),
48- allocators (allocators_ptr), owns_data(false ) {
48+ allocators (allocators_ptr), owns_data(false ), verify_max_key_len( false ) {
4949
5050 // FIXME: Use the new byte representation function to support nested types.
5151 for (idx_t i = 0 ; i < types.size (); i++) {
@@ -70,6 +70,12 @@ ART::ART(const string &name, const IndexConstraintType index_constraint_type, co
7070 }
7171 }
7272
73+ if (types.size () > 1 ) {
74+ verify_max_key_len = true ;
75+ } else if (types[0 ] == PhysicalType::VARCHAR) {
76+ verify_max_key_len = true ;
77+ }
78+
7379 // Initialize the allocators.
7480 SetPrefixCount (info);
7581 if (!allocators) {
@@ -380,11 +386,25 @@ void GenerateKeysInternal(ArenaAllocator &allocator, DataChunk &input, unsafe_ve
380386template <>
381387void ART::GenerateKeys<>(ArenaAllocator &allocator, DataChunk &input, unsafe_vector<ARTKey> &keys) {
382388 GenerateKeysInternal<false >(allocator, input, keys);
389+ if (!verify_max_key_len) {
390+ return ;
391+ }
392+ auto max_len = MAX_KEY_LEN * idx_t (prefix_count);
393+ for (idx_t i = 0 ; i < input.size (); i++) {
394+ keys[i].VerifyKeyLength (max_len);
395+ }
383396}
384397
385398template <>
386399void ART::GenerateKeys<true >(ArenaAllocator &allocator, DataChunk &input, unsafe_vector<ARTKey> &keys) {
387400 GenerateKeysInternal<true >(allocator, input, keys);
401+ if (!verify_max_key_len) {
402+ return ;
403+ }
404+ auto max_len = MAX_KEY_LEN * idx_t (prefix_count);
405+ for (idx_t i = 0 ; i < input.size (); i++) {
406+ keys[i].VerifyKeyLength (max_len);
407+ }
388408}
389409
390410void ART::GenerateKeyVectors (ArenaAllocator &allocator, DataChunk &input, Vector &row_ids, unsafe_vector<ARTKey> &keys,
@@ -976,6 +996,8 @@ bool ART::Scan(IndexScanState &state, const idx_t max_count, unsafe_vector<row_t
976996 D_ASSERT (scan_state.values [0 ].type ().InternalType () == types[0 ]);
977997 ArenaAllocator arena_allocator (Allocator::Get (db));
978998 auto key = ARTKey::CreateKey (arena_allocator, types[0 ], scan_state.values [0 ]);
999+ auto max_len = MAX_KEY_LEN * prefix_count;
1000+ key.VerifyKeyLength (max_len);
9791001
9801002 if (scan_state.values [1 ].IsNull ()) {
9811003 // Single predicate.
@@ -1000,6 +1022,8 @@ bool ART::Scan(IndexScanState &state, const idx_t max_count, unsafe_vector<row_t
10001022 lock_guard<mutex> l (lock);
10011023 D_ASSERT (scan_state.values [1 ].type ().InternalType () == types[0 ]);
10021024 auto upper_bound = ARTKey::CreateKey (arena_allocator, types[0 ], scan_state.values [1 ]);
1025+ upper_bound.VerifyKeyLength (max_len);
1026+
10031027 bool left_equal = scan_state.expressions [0 ] == ExpressionType ::COMPARE_GREATERTHANOREQUALTO;
10041028 bool right_equal = scan_state.expressions [1 ] == ExpressionType ::COMPARE_LESSTHANOREQUALTO;
10051029 return SearchCloseRange (key, upper_bound, left_equal, right_equal, max_count, row_ids);
@@ -1305,11 +1329,6 @@ void ART::SetPrefixCount(const IndexStorageInfo &info) {
13051329 return ;
13061330 }
13071331
1308- if (!IsUnique ()) {
1309- prefix_count = Prefix::ROW_ID_COUNT;
1310- return ;
1311- }
1312-
13131332 idx_t compound_size = 0 ;
13141333 for (const auto &type : types) {
13151334 compound_size += GetTypeIdSize (type);
0 commit comments