Skip to content

Commit 67d8e39

Browse files
authored
Ability to create an inactive index (#8091)
* Ability to create an inactive index * Extract inactive indices in dialect 1
1 parent a8f5bdb commit 67d8e39

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

doc/sql.extensions/README.ddl.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,3 +709,12 @@ CREATE PACKAGE BODY [IF NOT EXISTS] ...
709709
CREATE [GLOBAL] MAPPING [IF NOT EXISTS] ...
710710
ALTER TABLE <table> ADD [IF NOT EXISTS] <column name> ...
711711
ALTER TABLE <table> ADD CONSTRAINT [IF NOT EXISTS] <constraint name> ...
712+
713+
3) Creation of an inactive index
714+
715+
CREATE [UNIQUE] [ASC[ENDING] | DESC[ENDING]]
716+
INDEX indexname [{ACTIVE | INACTIVE}]
717+
ON tablename {(col [, col ...]) | COMPUTED BY (<expression>)}
718+
[WHERE <search_condition>]
719+
720+
'isql -x' generates script accordingly.

src/dsql/DdlNodes.epp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10062,7 +10062,7 @@ void CreateIndexNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch,
1006210062
definition.relation = relation->dsqlName;
1006310063
definition.unique = unique;
1006410064
definition.descending = descending;
10065-
definition.inactive = false;
10065+
definition.inactive = !active;
1006610066

1006710067
if (columns)
1006810068
{

src/dsql/DdlNodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,6 +1790,7 @@ class CreateIndexNode : public DdlNode
17901790
MetaName name;
17911791
bool unique;
17921792
bool descending;
1793+
bool active;
17931794
NestConst<RelationSourceNode> relation;
17941795
NestConst<ValueListNode> columns;
17951796
NestConst<ValueSourceClause> computed;

src/dsql/parse.y

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,18 +1546,19 @@ create_clause
15461546
node->createIfNotExistsOnly = $2;
15471547
$$ = node;
15481548
}
1549-
| unique_opt order_direction INDEX if_not_exists_opt symbol_index_name ON simple_table_name
1549+
| unique_opt order_direction INDEX if_not_exists_opt symbol_index_name index_active_opt ON simple_table_name
15501550
{
15511551
const auto node = newNode<CreateIndexNode>(*$5);
1552+
node->active = $6;
15521553
node->unique = $1;
15531554
node->descending = $2;
15541555
node->createIfNotExistsOnly = $4;
1555-
node->relation = $7;
1556+
node->relation = $8;
15561557
$$ = node;
15571558
}
1558-
index_definition(static_cast<CreateIndexNode*>($8))
1559+
index_definition(static_cast<CreateIndexNode*>($9))
15591560
{
1560-
$$ = $8;
1561+
$$ = $9;
15611562
}
15621563
| FUNCTION if_not_exists_opt function_clause
15631564
{
@@ -1753,6 +1754,12 @@ alter_exception_clause
17531754

17541755
// CREATE INDEX
17551756

1757+
%type <boolVal> index_active_opt
1758+
index_active_opt
1759+
: /* nothing */ { $$ = true; }
1760+
| index_active { $$ = $1; }
1761+
;
1762+
17561763
%type <boolVal> unique_opt
17571764
unique_opt
17581765
: /* nothing */ { $$ = false; }
@@ -4676,8 +4683,16 @@ drop_behaviour
46764683

46774684
%type <ddlNode> alter_index_clause
46784685
alter_index_clause
4679-
: symbol_index_name ACTIVE { $$ = newNode<AlterIndexNode>(*$1, true); }
4680-
| symbol_index_name INACTIVE { $$ = newNode<AlterIndexNode>(*$1, false); }
4686+
: symbol_index_name index_active
4687+
{
4688+
$$ = newNode<AlterIndexNode>(*$1, $2);
4689+
}
4690+
;
4691+
4692+
%type <boolVal> index_active
4693+
index_active
4694+
: ACTIVE { $$ = true; }
4695+
| INACTIVE { $$ = false; }
46814696
;
46824697

46834698
%type <ddlNode> alter_udf_clause

src/isql/extract.epp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3337,17 +3337,19 @@ static void list_indexes()
33373337
{
33383338
IUTILS_copy_SQL_id (IDX.RDB$INDEX_NAME, SQL_identifier, DBL_QUOTE);
33393339
IUTILS_copy_SQL_id (IDX.RDB$RELATION_NAME, SQL_identifier2, DBL_QUOTE);
3340-
isqlGlob.printf("CREATE%s%s INDEX %s ON %s",
3340+
isqlGlob.printf("CREATE%s%s INDEX %s%s ON %s",
33413341
(IDX.RDB$UNIQUE_FLAG ? " UNIQUE" : ""),
33423342
(IDX.RDB$INDEX_TYPE ? " DESCENDING" : ""),
33433343
SQL_identifier,
3344+
(IDX.RDB$INDEX_INACTIVE ? " INACTIVE" : ""),
33443345
SQL_identifier2);
33453346
}
33463347
else
3347-
isqlGlob.printf("CREATE%s%s INDEX %s ON %s",
3348+
isqlGlob.printf("CREATE%s%s INDEX %s%s ON %s",
33483349
(IDX.RDB$UNIQUE_FLAG ? " UNIQUE" : ""),
33493350
(IDX.RDB$INDEX_TYPE ? " DESCENDING" : ""),
33503351
IDX.RDB$INDEX_NAME,
3352+
(IDX.RDB$INDEX_INACTIVE ? " INACTIVE" : ""),
33513353
IDX.RDB$RELATION_NAME);
33523354

33533355
// Get index expression or column names

0 commit comments

Comments
 (0)