Skip to content

Commit

Permalink
Add test for concurrent index builds for hypercore
Browse files Browse the repository at this point in the history
Concurrent index builds are not supported for hypertables at all, so
this just adds tests that it fails with an error both when attempting
it on a hypertable and on a chunk using the `hypercore` table access
method.
  • Loading branch information
mkindahl committed Nov 21, 2024
1 parent f2663aa commit beb4326
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
5 changes: 4 additions & 1 deletion tsl/src/hypercore/hypercore_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -3081,7 +3081,10 @@ static void
hypercore_index_validate_scan(Relation compressionRelation, Relation indexRelation,
IndexInfo *indexInfo, Snapshot snapshot, ValidateIndexState *state)
{
FEATURE_NOT_SUPPORTED;
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("concurrent index creation on is not supported on tables using hypercore table "
"access method")));
}

/* ------------------------------------------------------------------------
Expand Down
17 changes: 15 additions & 2 deletions tsl/test/expected/hypercore.out
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ show timescaledb.hypercore_indexam_whitelist;
btree,hash
(1 row)

-- We need this to be able to create an index for a chunk as a default
-- user.
grant all on schema _timescaledb_internal to :ROLE_DEFAULT_PERM_USER;
set role :ROLE_DEFAULT_PERM_USER;
SET timescaledb.arrow_cache_maxsize = 4;
CREATE TABLE readings(
Expand Down Expand Up @@ -138,17 +141,27 @@ WHERE time = '2022-06-01'::timestamptz;

-- Create a new index on a compressed column
CREATE INDEX ON readings (location);
-- Check that we error out on unsupported index types
\set ON_ERROR_STOP 0
-- Check that we error out on unsupported index types
create index on readings using brin (device);
ERROR: index access method "brin" not supported
create index on readings using gin (jdata);
ERROR: index access method "gin" not supported
create index on readings using magicam (device);
ERROR: access method "magicam" does not exist
-- Check that we error out when trying to build index concurrently.
create index concurrently on readings (device);
ERROR: hypertables do not support concurrent index creation
create index concurrently invalid_index on :chunk (device);
ERROR: concurrent index creation on is not supported on tables using hypercore table access method
-- This will also create the index on the chunk (this is how it works,
-- see validate_index() in index.c for more information), but that
-- index is not valid, so we just drop it explicitly here to keep the
-- rest of the test clean.
drop index _timescaledb_internal.invalid_index;
\set ON_ERROR_STOP 1
-- Index added on location
SELECT * FROM test.show_indexes(:'chunk');
SELECT * FROM test.show_indexes(:'chunk') ORDER BY "Index"::text;
Index | Columns | Expr | Unique | Primary | Exclusion | Tablespace
--------------------------------------------------------------+------------+------+--------+---------+-----------+------------
_timescaledb_internal."1_1_readings_time_key" | {time} | | t | f | f |
Expand Down
16 changes: 14 additions & 2 deletions tsl/test/sql/hypercore.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

\c :TEST_DBNAME :ROLE_SUPERUSER
show timescaledb.hypercore_indexam_whitelist;
-- We need this to be able to create an index for a chunk as a default
-- user.
grant all on schema _timescaledb_internal to :ROLE_DEFAULT_PERM_USER;
set role :ROLE_DEFAULT_PERM_USER;

SET timescaledb.arrow_cache_maxsize = 4;
Expand Down Expand Up @@ -93,15 +96,24 @@ WHERE time = '2022-06-01'::timestamptz;
-- Create a new index on a compressed column
CREATE INDEX ON readings (location);

-- Check that we error out on unsupported index types
\set ON_ERROR_STOP 0
-- Check that we error out on unsupported index types
create index on readings using brin (device);
create index on readings using gin (jdata);
create index on readings using magicam (device);

-- Check that we error out when trying to build index concurrently.
create index concurrently on readings (device);
create index concurrently invalid_index on :chunk (device);
-- This will also create the index on the chunk (this is how it works,
-- see validate_index() in index.c for more information), but that
-- index is not valid, so we just drop it explicitly here to keep the
-- rest of the test clean.
drop index _timescaledb_internal.invalid_index;
\set ON_ERROR_STOP 1

-- Index added on location
SELECT * FROM test.show_indexes(:'chunk');
SELECT * FROM test.show_indexes(:'chunk') ORDER BY "Index"::text;

-- Query by location should be an index scan
EXPLAIN (verbose, costs off)
Expand Down

0 comments on commit beb4326

Please sign in to comment.