Skip to content
Open
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
22 changes: 18 additions & 4 deletions doc/sql.extensions/README.declared_local_temporary_tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Declared Local Temporary Tables are declared in the same declaration section as
DECLARE [LOCAL] TEMPORARY TABLE <table_name>
(
<column_definition> [, ...]
);
)
[[UNIQUE] [ASC | DESC] INDEX <index_name> (<column_name> [, ...])]...;
```

There is no `ON COMMIT` clause.
Expand All @@ -35,7 +36,8 @@ as
declare local temporary table t (
id integer not null,
val varchar(20)
);
)
index idx_t_id (id);
begin
insert into t(id, val) values (1, 'a');
insert into t(id, val) values (2, 'b');
Expand All @@ -59,7 +61,8 @@ create procedure p_count_values returns (n integer)
as
declare local temporary table t (
id integer not null
);
)
unique index uq_t_id (id);
begin
insert into t(id) values (1);
insert into t(id) values (2);
Expand Down Expand Up @@ -214,6 +217,17 @@ delete from t where ...;

They can be used in subqueries, joins and cursor loops like other record sources, subject to the restrictions below.

Indexes can be declared inline as part of the table declaration:

```sql
declare local temporary table t (
id integer not null,
val varchar(20)
)
index idx_t_id (id)
descending index idx_t_val_desc (val);
```

## Restrictions

Declared Local Temporary Tables intentionally support a small table definition surface.
Expand All @@ -237,7 +251,7 @@ Constraint restrictions:
Other restrictions:

- A single PSQL statement, procedure, function or trigger may declare at most 1024 local temporary tables.
- Indexes are not supported.
- Expression-based indexes and partial indexes are not supported.
- Triggers on declared local temporary tables are not supported.
- Explicit privileges are not supported.
- `ALTER TABLE`, `DROP TABLE`, `CREATE INDEX`, `ALTER INDEX` and `DROP INDEX` are not valid for declared local
Expand Down
22 changes: 11 additions & 11 deletions src/dsql/DdlNodes.epp
Original file line number Diff line number Diff line change
Expand Up @@ -7076,17 +7076,17 @@ DdlNode* RelationNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
case Clause::TYPE_ALTER_PUBLICATION:
break;

case Clause::TYPE_ADD_PACKAGED_TABLE_INDEX:
case Clause::TYPE_ADD_INLINE_TABLE_INDEX:
{
auto addPackagedTableIndexClause = static_cast<AddPackagedTableIndexClause*>(clause.getObject());
auto addInlineTableIndexClause = static_cast<AddInlineTableIndexClause*>(clause.getObject());

if (!addPackagedTableIndexClause->indexNode->relation)
if (!addInlineTableIndexClause->indexNode->relation)
{
addPackagedTableIndexClause->indexNode->relation = FB_NEW_POOL(dsqlScratch->getPool())
addInlineTableIndexClause->indexNode->relation = FB_NEW_POOL(dsqlScratch->getPool())
RelationSourceNode(dsqlScratch->getPool(), name);
}

addPackagedTableIndexClause->indexNode->dsqlPass(dsqlScratch);
addInlineTableIndexClause->indexNode->dsqlPass(dsqlScratch);
break;
}

Expand Down Expand Up @@ -7335,7 +7335,7 @@ void RelationNode::validateLttClauses(const Array<NestConst<Clause>>& clauses)
"Only NOT NULL constraints without names are supported on LOCAL TEMPORARY TABLEs");
break;

case Clause::TYPE_ADD_PACKAGED_TABLE_INDEX:
case Clause::TYPE_ADD_INLINE_TABLE_INDEX:
break;

default:
Expand Down Expand Up @@ -9864,14 +9864,14 @@ void CreateRelationNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScrat
static_cast<AddConstraintClause*>(i->getObject()), constraints);
break;

case Clause::TYPE_ADD_PACKAGED_TABLE_INDEX:
case Clause::TYPE_ADD_INLINE_TABLE_INDEX:
{
auto addPackagedTableIndexClause = static_cast<AddPackagedTableIndexClause*>(i->getObject());
const auto indexNode = addPackagedTableIndexClause->indexNode;
auto addInlineTableIndexClause = static_cast<AddInlineTableIndexClause*>(i->getObject());
const auto indexNode = addInlineTableIndexClause->indexNode;

if (!indexNode->relation)
{
addPackagedTableIndexClause->indexNode->relation = FB_NEW_POOL(dsqlScratch->getPool())
addInlineTableIndexClause->indexNode->relation = FB_NEW_POOL(dsqlScratch->getPool())
RelationSourceNode(dsqlScratch->getPool(), name);
}

Expand All @@ -9893,7 +9893,7 @@ void CreateRelationNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScrat
}

indexList.push(CreateIndexNode::store(tdbb, indexList.getPool(), transaction,
addPackagedTableIndexClause->indexNode->name, definition));
addInlineTableIndexClause->indexNode->name, definition));

break;
}
Expand Down
8 changes: 4 additions & 4 deletions src/dsql/DdlNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ class RelationNode : public DdlNode
TYPE_DROP_CONSTRAINT,
TYPE_ALTER_SQL_SECURITY,
TYPE_ALTER_PUBLICATION,
TYPE_ADD_PACKAGED_TABLE_INDEX
TYPE_ADD_INLINE_TABLE_INDEX
};

explicit Clause(MemoryPool& p, Type aType) noexcept
Expand Down Expand Up @@ -1487,10 +1487,10 @@ class RelationNode : public DdlNode
unsigned deleteAction;
};

struct AddPackagedTableIndexClause : public Clause
struct AddInlineTableIndexClause : public Clause
{
explicit AddPackagedTableIndexClause(MemoryPool& p, CreateIndexNode* aIndexNode)
: Clause(p, TYPE_ADD_PACKAGED_TABLE_INDEX),
explicit AddInlineTableIndexClause(MemoryPool& p, CreateIndexNode* aIndexNode)
: Clause(p, TYPE_ADD_INLINE_TABLE_INDEX),
indexNode(aIndexNode)
{
}
Expand Down
Loading
Loading