dbt-labs / dbt-labs/dbt-adapters

[Feature] create indexes on the new table before renaming during full refresh

Open
#837 0 comments 1 reaction 0 assignees View on GitHub
pkg:dbt-postgres type:enhancement
Dominant language
Python
Stars
233
Forks
362
Avg merge
3d 22h
Merged PRs (30d)
9

Description

### Is this your first time submitting a feature request?

- [x] I have read the [expectations for open source contributors](https://docs.getdbt.com/docs/contributing/oss-expectations)
- [x] I have searched the existing issues, and I could not find an existing issue for this feature
- [x] I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion

### Describe the feature

When DBT performs a full refresh on a model in Postgres, it:
1. Runs a CTAS to create a `__dbt_tmp` table
2. Issues a `alter table ... rename to ...` statement to swap it with the live table
3. Builds all indexes on the new table

This ordering is highly disruptive due to the lock that is held when indexes are created. On full refresh the dbt-postgres adapter should instead build all indexes (3) before renaming the table (2).

### Describe alternatives you've considered

_No response_

### Who will this benefit?

Everyone. It will make full refreshes less destructive to end users.

### Are you interested in contributing this feature?

Potentially. I would need to be pointed in the right direction.

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.