# Dbt temp table not optimized

**URL:** https://discourse.getdbt.com/t/dbt-temp-table-not-optimized/10694
**Category:** Help
**Created:** [November 8, 2023, 1:31pm UTC](https://discourse.getdbt.com/t/dbt-temp-table-not-optimized/10694 "2023-11-08T13:31:28Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![samimeher1981](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/samimeher1981/32/3225_2.png) [@samimeher1981](https://discourse.getdbt.com/u/samimeher1981)
#### Post date: [November 8, 2023, 1:31pm UTC](https://discourse.getdbt.com/t/dbt-temp-table-not-optimized/10694/1 "2023-11-08T13:31:28Z")

</div>

When we set materialization=incremental then dbt create a temp table and store all transformed data and then it delete data from the actual table based on primary key and insert same data from temp table match same primary key. The problem with dbt temp, it doesn’t have any index or partition when it joining data with a physical table with primary key having large volume of data it doesn’t not perform well. Can we crate our own temp table in dbt model while during model execution? Is there any other thing we can do to fast join the data since from temp table it’s a sequencial reading since it doesn’t not have index.

---

<div class="post-metadata">

### Author: ![a\_slack\_user](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/a_slack_user/32/1629_2.png) [@a\_slack\_user](https://discourse.getdbt.com/u/a_slack_user)
#### Post date: [November 8, 2023, 1:35pm UTC](https://discourse.getdbt.com/t/dbt-temp-table-not-optimized/10694/2 "2023-11-08T13:35:10Z")

</div>

What does your model’s yaml definition look like? Does `data_type: string(30)` not work under the column definition?

Note: `@Mike Stanley` originally [posted this reply in Slack](https://getdbt.slack.com/archives/CBSQTAPLG/p1699450503990199?thread_ts=1699450311.194549&cid=CBSQTAPLG). It might not have transferred perfectly.

---

<div class="post-metadata">

### Author: ![a\_slack\_user](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/a_slack_user/32/1629_2.png) [@a\_slack\_user](https://discourse.getdbt.com/u/a_slack_user)
#### Post date: [November 8, 2023, 1:35pm UTC](https://discourse.getdbt.com/t/dbt-temp-table-not-optimized/10694/3 "2023-11-08T13:35:21Z")

</div>

Wrong thread, sorry!

Note: `@Mike Stanley` originally [posted this reply in Slack](https://getdbt.slack.com/archives/CBSQTAPLG/p1699450515013509?thread_ts=1699450311.194549&cid=CBSQTAPLG). It might not have transferred perfectly.

---

<div class="post-metadata">

### Author: ![a\_slack\_user](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/a_slack_user/32/1629_2.png) [@a\_slack\_user](https://discourse.getdbt.com/u/a_slack_user)
#### Post date: [November 8, 2023, 1:36pm UTC](https://discourse.getdbt.com/t/dbt-temp-table-not-optimized/10694/4 "2023-11-08T13:36:59Z")

</div>

You need to look at the different incremental strategies. The default strategy and the alternatives available vary by adapter. You can also write your own strategies if none of the default ones suit you.

Note: `@Mike Stanley` originally [posted this reply in Slack](https://getdbt.slack.com/archives/CBSQTAPLG/p1699450612930889?thread_ts=1699450311.194549&cid=CBSQTAPLG). It might not have transferred perfectly.
