File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed
lib/active_record/connection_adapters/sqlserver Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change
1
+ ## Unreleased
2
+
3
+ #### Changed
4
+
5
+ - [ #1073 ] ( https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1073 ) Improve performance of view default function lookup
6
+
1
7
## v7.0.3.0
2
8
3
9
#### Fixed
Original file line number Diff line number Diff line change @@ -371,6 +371,15 @@ def column_definitions(table_name)
371
371
view_exists = view_exists? ( table_name )
372
372
view_tblnm = view_table_name ( table_name ) if view_exists
373
373
374
+ if view_exists
375
+ results = sp_executesql %{
376
+ SELECT c.COLUMN_NAME AS [name], c.COLUMN_DEFAULT AS [default]
377
+ FROM #{ database } .INFORMATION_SCHEMA.COLUMNS c
378
+ WHERE c.TABLE_NAME = #{ quote ( view_tblnm ) }
379
+ } . squish , "SCHEMA" , [ ]
380
+ default_functions = results . each . with_object ( { } ) { |row , out | out [ row [ "name" ] ] = row [ "default" ] } . compact
381
+ end
382
+
374
383
sql = column_definitions_sql ( database , identifier )
375
384
376
385
binds = [ ]
@@ -402,13 +411,8 @@ def column_definitions(table_name)
402
411
ci [ :default_function ] = begin
403
412
default = ci [ :default_value ]
404
413
if default . nil? && view_exists
405
- default = select_value %{
406
- SELECT c.COLUMN_DEFAULT
407
- FROM #{ database } .INFORMATION_SCHEMA.COLUMNS c
408
- WHERE
409
- c.TABLE_NAME = '#{ view_tblnm } '
410
- AND c.COLUMN_NAME = '#{ views_real_column_name ( table_name , ci [ :name ] ) } '
411
- } . squish , "SCHEMA"
414
+ view_column = views_real_column_name ( table_name , ci [ :name ] )
415
+ default = default_functions [ view_column ] if view_column . present?
412
416
end
413
417
case default
414
418
when nil
You can’t perform that action at this time.
0 commit comments