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

[CT-306] [Bug] Indexes config does not create indexes #4808

Closed
1 task done
cleare-cl opened this issue Mar 1, 2022 · 7 comments
Closed
1 task done

[CT-306] [Bug] Indexes config does not create indexes #4808

cleare-cl opened this issue Mar 1, 2022 · 7 comments
Labels
bug Something isn't working postgres stale Issues that have gone stale Team:Adapters Issues designated for the adapter area of the code

Comments

@cleare-cl
Copy link

cleare-cl commented Mar 1, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

The config for index creation in postgres developed in dbt-labs/dbt-core#3106 does not create indexes.

We have tried different configuration methods, including specifying different uniqueness of the indexes on the columns as well as running it only with one column.

The compiled dbt SQL did not include create index statement.

Expected Behavior

The indexes configuration in the model creates indexes of the specified columns when ran.

Steps To Reproduce

  1. In a dbt model, set the indexes configuration

{{
config(
materialized = 'table',
indexes=[ {'columns': ['column1', 'column2', 'column3'] } ]
)
}}

  1. Run the model

Relevant log output

No response

Environment

- OS: MacOS
- Python: 3.9.10
- dbt: 1.0.3
- Postgres: 14.2

What database are you using dbt with?

postgres

Additional Context

No response

@cleare-cl cleare-cl added bug Something isn't working triage labels Mar 1, 2022
@github-actions github-actions bot changed the title [Bug] Indexes config does not create indexes [CT-306] [Bug] Indexes config does not create indexes Mar 1, 2022
@jtcohen6 jtcohen6 added postgres Team:Adapters Issues designated for the adapter area of the code labels Mar 2, 2022
@jtcohen6
Copy link
Contributor

jtcohen6 commented May 3, 2022

@cleare-cl Thanks for opening, and sorry for the delay getting back to you on this one!

The compiled dbt SQL did not include create index statement.

To clarify, did you try running the model (dbt run), and see that the create index statement was missing from the logs (logs/dbt.log), and that the index was indeed missing within Postgres?

Or was it that, after dbt compile or dbt run, you checked the "compiled SQL" for that model (such as target/compiled/.../model_with_indexes.sql), and noticed that it didn't contain any create index statements?

Today, dbt's "compiled SQL" includes just the compiled SQL written within that model. It doesn't include the "helper" statements within the materialization that persist docs, create indexes, move temp/backup tables out of the way, and so on. By a similar token, dbt's "run SQL" includes only the "main" statement run during the materialization (create table, insert into, etc). The creation of indexes happens in a separate statement afterward:

There's been a long-lived discussion about supporting a "dry run" mode for materializations, with the idea that dbt should be able to print out everything it plans to do during the process of materializing a model: #4456

@olia-cl
Copy link

olia-cl commented Jul 18, 2022

@jtcohen6 , thank you for your answer and sorry for the delay from my side.

I tried both: dbt compile and to run the model with dbt run. In both cases no indexes were created.

Initially I found out that the indexes configuration does not work by replacing the index macro with the new index configuration within the model. After running the model the existing indexes in postgres, that were previously created by the macro, were gone. After the second run no indexes were to be found. The create index statement was also missing in the logs/dbt.log.

After that I tried dbt compile and the index statement was also missing in the compiled SQL.

@jtcohen6
Copy link
Contributor

@olia-cl Is there any chance you have custom materialization macros in your project, overriding the ones that ship within dbt-core's global project? The calls to the create_indexes macro are here in the default table and incremental materializations:

{% if existing_relation is none or existing_relation.is_view or should_full_refresh() %}
{% do create_indexes(target_relation) %}
{% endif %}

@jtcohen6 jtcohen6 removed the triage label Jul 18, 2022
@github-actions
Copy link
Contributor

This issue has been marked as Stale because it has been open for 180 days with no activity. If you would like the issue to remain open, please comment on the issue or else it will be closed in 7 days.

@github-actions github-actions bot added the stale Issues that have gone stale label Jan 15, 2023
@github-actions
Copy link
Contributor

Although we are closing this issue as stale, it's not gone forever. Issues can be reopened if there is renewed community interest. Just add a comment to notify the maintainers.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 22, 2023
@wesleyguirra
Copy link

I'm having the same issue

@datasalaryman
Copy link

Having this issue now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working postgres stale Issues that have gone stale Team:Adapters Issues designated for the adapter area of the code
Projects
None yet
Development

No branches or pull requests

5 participants