Skip to content

Declared Local Temporary Tables in PSQL#9058

Open
asfernandes wants to merge 7 commits into
masterfrom
work/ltt
Open

Declared Local Temporary Tables in PSQL#9058
asfernandes wants to merge 7 commits into
masterfrom
work/ltt

Conversation

@asfernandes

Copy link
Copy Markdown
Member

No description provided.

@AlexBekhtin

Copy link
Copy Markdown

Is infinite execution correct by design?

execute block returns (n integer)
as
    declare local temporary table t (
        id integer not null
    );
begin
     insert into t(id)    
     values(1);

     insert into t(id) 
     select id from t;

    select count(*) from t into n;
    suspend;
end!

@asfernandes

Copy link
Copy Markdown
Member Author

Is infinite execution correct by design?

No, current local table blr (as used for RETURNING) is fragile.
I'm reviewing the implementation details.

@sim1984

sim1984 commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Please add documentation about declared ltt restrictions, specifically the number of LTTs per operator.

Could you add the ability to declare indexes for such tables?

@asfernandes

Copy link
Copy Markdown
Member Author

Could you add the ability to declare indexes for such tables?

I'm working on it. Will be added in another PR.

@dyemanov dyemanov self-requested a review June 22, 2026 12:32
Comment thread doc/sql.extensions/README.declared_local_temporary_tables.md Outdated
Comment thread src/dsql/dsql.h Outdated
Comment thread src/jrd/Statement.cpp
Comment thread src/jrd/Statement.cpp
Comment thread src/jrd/Statement.cpp Outdated
Comment thread src/jrd/Savepoint.cpp Outdated
Comment thread src/jrd/Relation.h
Comment thread src/dsql/StmtNodes.cpp Outdated
Comment thread src/dsql/StmtNodes.cpp

const Format* format = rpb->rpb_relation->currentFormat(tdbb);
Record* record = VIO_record(tdbb, rpb, format, tdbb->getDefaultPool());
const Format* format = relation ? rpb->rpb_relation->currentFormat(tdbb) : localTable->format.getObject();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please explain why relation may be missing here (and other similar methods)? This seems to seriously complicate the logic.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Multi-row RETURNING uses an old implementation of "local table" based in RecordBuffer.

Comment thread src/dsql/StmtNodes.cpp Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants