Skip to content

Commit d4ff3ac

Browse files
authored
Merge pull request #402 from dbt-msft/nolock-per-adapter
make nolock overridable for child adapters
2 parents f9cbe48 + 56152bc commit d4ff3ac

File tree

5 files changed

+26
-20
lines changed

5 files changed

+26
-20
lines changed

dbt/include/sqlserver/macros/adapters/apply_grants.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
select
33
GRANTEE as grantee,
44
PRIVILEGE_TYPE as privilege_type
5-
from INFORMATION_SCHEMA.TABLE_PRIVILEGES with (nolock)
5+
from INFORMATION_SCHEMA.TABLE_PRIVILEGES {{ information_schema_hints() }}
66
where TABLE_CATALOG = '{{ relation.database }}'
77
and TABLE_SCHEMA = '{{ relation.schema }}'
88
and TABLE_NAME = '{{ relation.identifier }}'

dbt/include/sqlserver/macros/adapters/columns.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
c.max_length as character_maximum_length,
1010
c.precision as numeric_precision,
1111
c.scale as numeric_scale
12-
from [{{ 'tempdb' if '#' in relation.identifier else relation.database }}].sys.columns c with (nolock)
13-
inner join sys.types t with (nolock)
12+
from [{{ 'tempdb' if '#' in relation.identifier else relation.database }}].sys.columns c {{ information_schema_hints() }}
13+
inner join sys.types t {{ information_schema_hints() }}
1414
on c.user_type_id = t.user_type_id
1515
where c.object_id = object_id('{{ 'tempdb..' ~ relation.include(database=false, schema=false) if '#' in relation.identifier else relation }}')
1616
)

dbt/include/sqlserver/macros/adapters/indexes.sql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use [{{ relation.database }}];
66
if EXISTS (
77
SELECT *
8-
FROM sys.indexes with (nolock)
8+
FROM sys.indexes {{ information_schema_hints() }}
99
WHERE name = '{{cci_name}}'
1010
AND object_id=object_id('{{relation_name}}')
1111
)
@@ -33,8 +33,8 @@
3333
declare @drop_xml_indexes nvarchar(max);
3434
select @drop_xml_indexes = (
3535
select 'IF INDEXPROPERTY(' + CONVERT(VARCHAR(MAX), sys.tables.[object_id]) + ', ''' + sys.indexes.[name] + ''', ''IndexId'') IS NOT NULL DROP INDEX [' + sys.indexes.[name] + '] ON ' + '[' + SCHEMA_NAME(sys.tables.[schema_id]) + '].[' + OBJECT_NAME(sys.tables.[object_id]) + ']; '
36-
from sys.indexes with (nolock)
37-
inner join sys.tables with (nolock)
36+
from sys.indexes {{ information_schema_hints() }}
37+
inner join sys.tables {{ information_schema_hints() }}
3838
on sys.indexes.object_id = sys.tables.object_id
3939
where sys.indexes.[name] is not null
4040
and sys.indexes.type_desc = 'XML'
@@ -54,8 +54,8 @@ select @drop_xml_indexes = (
5454
declare @drop_spatial_indexes nvarchar(max);
5555
select @drop_spatial_indexes = (
5656
select 'IF INDEXPROPERTY(' + CONVERT(VARCHAR(MAX), sys.tables.[object_id]) + ', ''' + sys.indexes.[name] + ''', ''IndexId'') IS NOT NULL DROP INDEX [' + sys.indexes.[name] + '] ON ' + '[' + SCHEMA_NAME(sys.tables.[schema_id]) + '].[' + OBJECT_NAME(sys.tables.[object_id]) + ']; '
57-
from sys.indexes with (nolock)
58-
inner join sys.tables with (nolock)
57+
from sys.indexes {{ information_schema_hints() }}
58+
inner join sys.tables {{ information_schema_hints() }}
5959
on sys.indexes.object_id = sys.tables.object_id
6060
where sys.indexes.[name] is not null
6161
and sys.indexes.type_desc = 'Spatial'
@@ -119,8 +119,8 @@ select @drop_pk_constraints = (
119119
declare @drop_remaining_indexes_last nvarchar(max);
120120
select @drop_remaining_indexes_last = (
121121
select 'IF INDEXPROPERTY(' + CONVERT(VARCHAR(MAX), sys.tables.[object_id]) + ', ''' + sys.indexes.[name] + ''', ''IndexId'') IS NOT NULL DROP INDEX [' + sys.indexes.[name] + '] ON ' + '[' + SCHEMA_NAME(sys.tables.[schema_id]) + '].[' + OBJECT_NAME(sys.tables.[object_id]) + ']; '
122-
from sys.indexes with (nolock)
123-
inner join sys.tables with (nolock)
122+
from sys.indexes {{ information_schema_hints() }}
123+
inner join sys.tables {{ information_schema_hints() }}
124124
on sys.indexes.object_id = sys.tables.object_id
125125
where sys.indexes.[name] is not null
126126
and sys.tables.[name] = '{{ this.table }}'
@@ -137,7 +137,7 @@ select @drop_remaining_indexes_last = (
137137
{% set idx_name = "clustered_" + local_md5(columns | join("_")) %}
138138

139139
if not exists(select *
140-
from sys.indexes with (nolock)
140+
from sys.indexes {{ information_schema_hints() }}
141141
where name = '{{ idx_name }}'
142142
and object_id = OBJECT_ID('{{ this }}')
143143
)
@@ -170,7 +170,7 @@ end
170170
{% endif %}
171171

172172
if not exists(select *
173-
from sys.indexes with (nolock)
173+
from sys.indexes {{ information_schema_hints() }}
174174
where name = '{{ idx_name }}'
175175
and object_id = OBJECT_ID('{{ this }}')
176176
)

dbt/include/sqlserver/macros/adapters/metadata.sql

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
{% macro information_schema_hints() %}
2+
{{ return(adapter.dispatch('information_schema_hints')()) }}
3+
{% endmacro %}
4+
5+
{% macro default__information_schema_hints() %}{% endmacro %}
6+
{% macro sqlserver__information_schema_hints() %}with (nolock){% endmacro %}
17

28
{% macro sqlserver__get_catalog(information_schemas, schemas) -%}
39

@@ -9,7 +15,7 @@
915
name as principal_name,
1016
principal_id as principal_id
1117
from
12-
sys.database_principals with (nolock)
18+
sys.database_principals {{ information_schema_hints() }}
1319
),
1420

1521
schemas as (
@@ -18,7 +24,7 @@
1824
schema_id as schema_id,
1925
principal_id as principal_id
2026
from
21-
sys.schemas with (nolock)
27+
sys.schemas {{ information_schema_hints() }}
2228
),
2329

2430
tables as (
@@ -28,7 +34,7 @@
2834
principal_id as principal_id,
2935
'BASE TABLE' as table_type
3036
from
31-
sys.tables with (nolock)
37+
sys.tables {{ information_schema_hints() }}
3238
),
3339

3440
tables_with_metadata as (
@@ -49,7 +55,7 @@
4955
principal_id as principal_id,
5056
'VIEW' as table_type
5157
from
52-
sys.views with (nolock)
58+
sys.views {{ information_schema_hints() }}
5359
),
5460

5561
views_with_metadata as (
@@ -92,7 +98,7 @@
9298
column_name,
9399
ordinal_position as column_index,
94100
data_type as column_type
95-
from INFORMATION_SCHEMA.COLUMNS with (nolock)
101+
from INFORMATION_SCHEMA.COLUMNS {{ information_schema_hints() }}
96102

97103
)
98104

@@ -129,7 +135,7 @@
129135
{% call statement('list_schemas', fetch_result=True, auto_begin=False) -%}
130136
USE {{ database }};
131137
select name as [schema]
132-
from sys.schemas with (nolock)
138+
from sys.schemas {{ information_schema_hints() }}
133139
{% endcall %}
134140
{{ return(load_result('list_schemas').table) }}
135141
{% endmacro %}
@@ -153,7 +159,7 @@
153159
else table_type
154160
end as table_type
155161

156-
from [{{ schema_relation.database }}].INFORMATION_SCHEMA.TABLES with (nolock)
162+
from [{{ schema_relation.database }}].INFORMATION_SCHEMA.TABLES {{ information_schema_hints() }}
157163
where table_schema = '{{ schema_relation.schema }}'
158164
{% endcall %}
159165
{{ return(load_result('list_relations_without_caching').table) }}

dbt/include/sqlserver/macros/adapters/relation.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
EXEC sp_rename '{{ from_relation.schema }}.{{ from_relation.identifier }}', '{{ to_relation.identifier }}'
4646
IF EXISTS(
4747
SELECT *
48-
FROM sys.indexes with (nolock)
48+
FROM sys.indexes {{ information_schema_hints() }}
4949
WHERE name='{{ from_relation.schema }}_{{ from_relation.identifier }}_cci' and object_id = OBJECT_ID('{{ from_relation.schema }}.{{ to_relation.identifier }}'))
5050
EXEC sp_rename N'{{ from_relation.schema }}.{{ to_relation.identifier }}.{{ from_relation.schema }}_{{ from_relation.identifier }}_cci', N'{{ from_relation.schema }}_{{ to_relation.identifier }}_cci', N'INDEX'
5151
{%- endcall %}

0 commit comments

Comments
 (0)