Skip to content

Commit

Permalink
On CREATE INDEX on AOCO table, check WHERE clause for columns to scan.
Browse files Browse the repository at this point in the history
Fixes github issue #9022

Reviewed-by: Asim R P <apraveen@pivotal.io>
  • Loading branch information
hlinnaka committed Nov 24, 2019
1 parent 1f84572 commit 769d176
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/backend/catalog/index.c
Expand Up @@ -3058,6 +3058,9 @@ IndexBuildAppendOnlyColScan(Relation parentRelation,
GetNeededColumnsForScan((Node *)indexInfo->ii_Expressions,
proj,
parentRelation->rd_att->natts);
GetNeededColumnsForScan((Node *)indexInfo->ii_Predicate,
proj,
parentRelation->rd_att->natts);
}

else
Expand Down
26 changes: 26 additions & 0 deletions src/test/regress/input/aocs.source
Expand Up @@ -557,6 +557,32 @@ a.c1
;

drop table bms_ao_bug;


-- When an index is created on an AOCO table, test that we correctly scan
-- all the columns that are needed to build the index.
create table aocs_index_cols (id int4, a text, b text) with (appendonly=true, orientation=column);
insert into aocs_index_cols values (1, 'foo', 'bar');

-- Create an index on the table. This is the first index on the table, so it
-- creates the ao block directory, and scans all columns.
create index on aocs_index_cols (id);

-- Create a partial index. This index needs to scan two columns; one is used
-- as the index column, and the other in the WHERE clause.
create index on aocs_index_cols (id) WHERE a like 'f%';

-- Also try an expression index.
create index on aocs_index_cols (length(b));

-- Check that the row is found using all the indexes.
set enable_seqscan=off;
select * from aocs_index_cols where id = 1;
select * from aocs_index_cols where a like 'f%';
select * from aocs_index_cols where length(b) = 3;
reset enable_seqscan;


-- Small content as well as bulk dense content headers need to be used
-- appropriately if compression is found to be not useful. This test
-- cover a bug where only small content headers were generated in such
Expand Down
33 changes: 33 additions & 0 deletions src/test/regress/output/aocs.source
Expand Up @@ -1143,6 +1143,39 @@ a.c1
(1 row)

drop table bms_ao_bug;
-- When an index is created on an AOCO table, test that we correctly scan
-- all the columns that are needed to build the index.
create table aocs_index_cols (id int4, a text, b text) with (appendonly=true, orientation=column);
insert into aocs_index_cols values (1, 'foo', 'bar');
-- Create an index on the table. This is the first index on the table, so it
-- creates the ao block directory, and scans all columns.
create index on aocs_index_cols (id);
-- Create a partial index. This index needs to scan two columns; one is used
-- as the index column, and the other in the WHERE clause.
create index on aocs_index_cols (id) WHERE a like 'f%';
-- Also try an expression index.
create index on aocs_index_cols (length(b));
-- Check that the row is found using all the indexes.
set enable_seqscan=off;
select * from aocs_index_cols where id = 1;
id | a | b
----+-----+-----
1 | foo | bar
(1 row)

select * from aocs_index_cols where a like 'f%';
id | a | b
----+-----+-----
1 | foo | bar
(1 row)

select * from aocs_index_cols where length(b) = 3;
id | a | b
----+-----+-----
1 | foo | bar
(1 row)

reset enable_seqscan;
-- Small content as well as bulk dense content headers need to be used
-- appropriately if compression is found to be not useful. This test
-- cover a bug where only small content headers were generated in such
Expand Down

0 comments on commit 769d176

Please sign in to comment.