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

[Bug] Creating nonclustered indexes in a SQL Server materialized table is resulting in an orphaned clustered columnstore index #10964

Closed
2 tasks done
ianlcassidy opened this issue Nov 1, 2024 · 3 comments
Labels
adapter_plugins Issues relating to third-party adapter plugins bug Something isn't working wontfix Not a bug or out of scope for dbt-core

Comments

@ianlcassidy
Copy link

Is this a new bug in dbt-core?

  • I believe this is a new bug in dbt-core
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

When creating a materialized table and specifying nonclustered indexes in the config post-hook, a clustered columnstore index is created on the dbt tmp table and then the tmp table is renamed. This is resulting in our database backup failing (we use Commvault) because the clustered columnstore index is "orphaned."

Expected Behavior

We expect the clustered columnstore index to be created after the tmp table is renamed, similar to how the nonclustered indexes are created. We have tested this theory by modifying the execution steps in the dbt.log file and our database backup succeeds.

Steps To Reproduce

  1. use dbt to create an arbitrary materialized table using the sql server adaptor
  2. specify at least one nonclustered index in the config post-hook
  3. run dbt on the single model
  4. inspect the DDL or look at the indexes created including the clustered columnstore index

Relevant log output

use [DATABASE];
if EXISTS (
   SELECT *
   FROM sys.indexes with (nolock)
   WHERE name = 'SCHEMA_TABLE__dbt_tmp_cci'
   AND object_id=object_id('SCHEMA_TABLE__dbt_tmp')
)
DROP index "SCHEMA"."TABLE__dbt_tmp".SCHEMA_TABLE__dbt_tmp_cci
CREATE CLUSTERED COLUMNSTORE INDEX SCHEMA_TABLE__dbt_tmp_cci    <---- index created on tmp table
ON "SCHEMA"."TABLE__dbt_tmp"

USE [DATABASE];
      EXEC sp_rename 'SCHEMA.TABLE', 'TABLE__dbt_backup'

USE [USB-DataScience];
      EXEC sp_rename 'SCHEMA.TABLE__dbt_tmp', 'TABLE'    <---- tmp table renamed

if not exists(select *
              from sys.indexes with (nolock)
              where name = 'nonclustered_6eb6a6764d9714280e37441d1ac3d5ae'
              and object_id = OBJECT_ID('"DATABASE"."SCHEMA"."TABLE"')
)
begin
create nonclustered index   <--- index created on actual table
       nonclustered_6eb6a6764d9714280e37441d1ac3d5ae
       on "DATABASE"."SCHEMA"."TABLE" ([FIELD])
        
end

Environment

- OS: Windows 10
- Python: 3.11.9
- dbt: 1.8.7

Which database adapter are you using with dbt?

other (mention it in "Additional Context")

Additional Context

We are using the dbt SQL Server adapter.

Sample dbt model code:

{{
    config({
        "materialized": "table",
        "post-hook": [
            "{{ create_nonclustered_index(columns = ['FIELD']) }}",
        ],
    })
}}

select
  *
from
  {{ source('SCHEMA', 'TABLE') }};
@ianlcassidy ianlcassidy added bug Something isn't working triage labels Nov 1, 2024
@dbeatty10 dbeatty10 added the adapter_plugins Issues relating to third-party adapter plugins label Nov 1, 2024
@dbeatty10
Copy link
Contributor

@ianlcassidy this looks to me like it is specific to the dbt-sqlserver adapter, specifically, the create_nonclustered_index macro it provides.

Could you open an issue here instead?

@dbeatty10 dbeatty10 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 1, 2024
@dbeatty10 dbeatty10 added wontfix Not a bug or out of scope for dbt-core and removed triage labels Nov 1, 2024
@ianlcassidy
Copy link
Author

@dbeatty10 - apologies. will open an issue in the other repo.

@dbeatty10
Copy link
Contributor

@dbeatty10 - apologies. will open an issue in the other repo.

No worries @ianlcassidy ! Just want to get you to the right spot so it can be investigated further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
adapter_plugins Issues relating to third-party adapter plugins bug Something isn't working wontfix Not a bug or out of scope for dbt-core
Projects
None yet
Development

No branches or pull requests

2 participants