Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to create an inactive index #8091

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/sql.extensions/README.ddl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -708,3 +708,12 @@ CREATE PACKAGE BODY [IF NOT EXISTS] ...
CREATE [GLOBAL] MAPPING [IF NOT EXISTS] ...
ALTER TABLE <table> ADD [IF NOT EXISTS] <column name> ...
ALTER TABLE <table> ADD CONSTRAINT [IF NOT EXISTS] <constraint name> ...

3) Creation of an inactive index

CREATE [UNIQUE] [ASC[ENDING] | DESC[ENDING]]
INDEX indexname [{ACTIVE | INACTIVE}]
ON tablename {(col [, col ...]) | COMPUTED BY (<expression>)}
[WHERE <search_condition>]

'isql -x' generates script accordingly.
2 changes: 1 addition & 1 deletion src/dsql/DdlNodes.epp
Original file line number Diff line number Diff line change
Expand Up @@ -10062,7 +10062,7 @@ void CreateIndexNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScratch,
definition.relation = relation->dsqlName;
definition.unique = unique;
definition.descending = descending;
definition.inactive = false;
definition.inactive = !active;

if (columns)
{
Expand Down
1 change: 1 addition & 0 deletions src/dsql/DdlNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,7 @@ class CreateIndexNode : public DdlNode
MetaName name;
bool unique;
bool descending;
bool active;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this field is not initialized.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is unconditionally assigned in parse.y.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be assigned in constructor (or in the field) like all others fields of all others classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assigning value twice in row is just a waste of time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you still wonder why most of your PRs nobody wants to review and/or accept ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have a testcase that shows a problem - share it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny (not).
You should learn and follow basic rules before attempt to contribute something.

NestConst<RelationSourceNode> relation;
NestConst<ValueListNode> columns;
NestConst<ValueSourceClause> computed;
Expand Down
27 changes: 21 additions & 6 deletions src/dsql/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -1546,18 +1546,19 @@ create_clause
node->createIfNotExistsOnly = $2;
$$ = node;
}
| unique_opt order_direction INDEX if_not_exists_opt symbol_index_name ON simple_table_name
| unique_opt order_direction INDEX if_not_exists_opt symbol_index_name index_active_opt ON simple_table_name
{
const auto node = newNode<CreateIndexNode>(*$5);
node->active = $6;
node->unique = $1;
node->descending = $2;
node->createIfNotExistsOnly = $4;
node->relation = $7;
node->relation = $8;
$$ = node;
}
index_definition(static_cast<CreateIndexNode*>($8))
index_definition(static_cast<CreateIndexNode*>($9))
{
$$ = $8;
$$ = $9;
}
| FUNCTION if_not_exists_opt function_clause
{
Expand Down Expand Up @@ -1753,6 +1754,12 @@ alter_exception_clause

// CREATE INDEX

%type <boolVal> index_active_opt
index_active_opt
: /* nothing */ { $$ = true; }
| index_active { $$ = $1; }
;

%type <boolVal> unique_opt
unique_opt
: /* nothing */ { $$ = false; }
Expand Down Expand Up @@ -4676,8 +4683,16 @@ drop_behaviour

%type <ddlNode> alter_index_clause
alter_index_clause
: symbol_index_name ACTIVE { $$ = newNode<AlterIndexNode>(*$1, true); }
| symbol_index_name INACTIVE { $$ = newNode<AlterIndexNode>(*$1, false); }
: symbol_index_name index_active
{
$$ = newNode<AlterIndexNode>(*$1, $2);
}
;

%type <boolVal> index_active
index_active
: ACTIVE { $$ = true; }
| INACTIVE { $$ = false; }
;

%type <ddlNode> alter_udf_clause
Expand Down
6 changes: 4 additions & 2 deletions src/isql/extract.epp
Original file line number Diff line number Diff line change
Expand Up @@ -3337,17 +3337,19 @@ static void list_indexes()
{
IUTILS_copy_SQL_id (IDX.RDB$INDEX_NAME, SQL_identifier, DBL_QUOTE);
IUTILS_copy_SQL_id (IDX.RDB$RELATION_NAME, SQL_identifier2, DBL_QUOTE);
isqlGlob.printf("CREATE%s%s INDEX %s ON %s",
isqlGlob.printf("CREATE%s%s INDEX %s%s ON %s",
(IDX.RDB$UNIQUE_FLAG ? " UNIQUE" : ""),
(IDX.RDB$INDEX_TYPE ? " DESCENDING" : ""),
SQL_identifier,
(IDX.RDB$INDEX_INACTIVE ? " INACTIVE" : ""),
SQL_identifier2);
}
else
isqlGlob.printf("CREATE%s%s INDEX %s ON %s",
isqlGlob.printf("CREATE%s%s INDEX %s%s ON %s",
(IDX.RDB$UNIQUE_FLAG ? " UNIQUE" : ""),
(IDX.RDB$INDEX_TYPE ? " DESCENDING" : ""),
IDX.RDB$INDEX_NAME,
(IDX.RDB$INDEX_INACTIVE ? " INACTIVE" : ""),
IDX.RDB$RELATION_NAME);

// Get index expression or column names
Expand Down