Skip to content

Commit

Permalink
fixed fulltext index creation logic for (babelfish-for-postgresql#2072)
Browse files Browse the repository at this point in the history
This commit fixes an issue when we execute the following query to create a unique index during table creation and when we use that index name for fulltext index creation, it was failing.

CREATE TABLE tableName(ID INT NOT NULL CONSTRAINT indexName PRIMARY KEY, txt TEXT);
CREATE FULLTEXT INDEX ON tableName(txt) KEY INDEX indexName;
GO

This was failing because we were only checking for a hashed unique index name not a simple index name during fulltext index creation and hence getting exception.

Issues Resolved
JIRA: BABEL-4383
Signed-off-by: Roshan Kanwar [email protected]
  • Loading branch information
roshan0708 committed Nov 28, 2023
1 parent c57e8bc commit af035ca
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion contrib/babelfishpg_tsql/src/pl_exec-2.c
Original file line number Diff line number Diff line change
Expand Up @@ -3804,7 +3804,7 @@ exec_stmt_fulltextindex(PLtsql_execstate *estate, PLtsql_stmt_fulltextindex *stm
if (is_create)
{
uniq_index_name = construct_unique_index_name((char *) stmt->index_name, table_name);
if(is_unique_index(relid, (const char *) uniq_index_name))
if(is_unique_index(relid, (const char *) uniq_index_name) || is_unique_index(relid, (const char *)stmt->index_name))
{
column_name = stmt->column_name;
ft_index_name = construct_unique_index_name("ft_index", table_name);
Expand Down
3 changes: 3 additions & 0 deletions contrib/babelfishpg_tsql/src/pltsql_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1824,7 +1824,10 @@ is_unique_index(Oid relid, const char *index_name)
{
unique_key_count++;
if (unique_key_count > 1)
{
ReleaseSysCache(attTuple);
break;
}
}
}
ReleaseSysCache(attTuple);
Expand Down
7 changes: 2 additions & 5 deletions test/JDBC/expected/FULLTEXT_INDEX-vu-prepare.out
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ignore


-- Index creation on different character data type columns
CREATE TABLE fti_table_t1(id int NOT NULL, a text);
CREATE TABLE fti_table_t1(id int NOT NULL constraint pk_mytexts primary key, a text);
GO

-- should throw syntax error for NULL index name
Expand All @@ -81,10 +81,7 @@ GO
~~ERROR (Message: '"ix_t1_a"' is not a valid index to enforce a full-text search key. A full-text search key must be a unique, non-nullable, single-column index which is not offline, is not defined on a non-deterministic or imprecise nonpersisted computed column, does not have a filter, and has maximum size of 900 bytes. Choose another index for the full-text key.)~~


CREATE UNIQUE INDEX IX_t1_a ON fti_table_t1(id);
GO

CREATE FULLTEXT INDEX ON fti_table_t1(a) KEY INDEX IX_t1_a;
CREATE FULLTEXT INDEX ON fti_table_t1(a) KEY INDEX pk_mytexts;
GO

CREATE TABLE fti_table_t2(id int not null, b char(10));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ SELECT set_config('babelfishpg_tsql.escape_hatch_fulltext', 'ignore', 'false')
GO

-- Index creation on different character data type columns
CREATE TABLE fti_table_t1(id int NOT NULL, a text);
CREATE TABLE fti_table_t1(id int NOT NULL constraint pk_mytexts primary key, a text);
GO

-- should throw syntax error for NULL index name
Expand All @@ -49,10 +49,7 @@ GO
CREATE FULLTEXT INDEX ON fti_table_t1(a) KEY INDEX IX_t1_a;
GO

CREATE UNIQUE INDEX IX_t1_a ON fti_table_t1(id);
GO

CREATE FULLTEXT INDEX ON fti_table_t1(a) KEY INDEX IX_t1_a;
CREATE FULLTEXT INDEX ON fti_table_t1(a) KEY INDEX pk_mytexts;
GO

CREATE TABLE fti_table_t2(id int not null, b char(10));
Expand Down

0 comments on commit af035ca

Please sign in to comment.