Closed AlexJBisping closed 4 years ago
I was able to work around this by using Class.all.each instead of Class.find_each but I would rather use find_each to avoid OOM on larger tables.
Hi! Although I did find a workaround, it isn't ideal. Is there a more fitting place for the above issue? Can I provide any more details?
Thank you for the incredible library, I really appreciate everyone that has contributed!
Environment
Operating System
Running on: Distributor ID: Ubuntu Description: Ubuntu 18.04.3 LTS Release: 18.04 Codename: bionic Linux ip-10-0-6-26 4.15.0-1065-aws #69-Ubuntu SMP Thu Mar 26 02:17:29 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Connecting to: Windows 10 on EC2 running Windows Server 2019 and Sql Server Developer 2019.
FreeTDS Version
1.2.3
Description
Error: TinyTds::Error: Incorrect syntax near the keyword 'ASC'
When a table has a compound primary key and tinytds is selecting all values from the table, it combines the columns of the compound primary key and throws the above error with the below backtrace.
Here is the compound primary key definition: ALTER TABLE [dbo].[Rollup_Records] ADD CONSTRAINT [PK_Rollup_Records] PRIMARY KEY CLUSTERED ( [candidate_id] ASC, [rollup_name] ASC )
I tracked the issue down to /activerecord-sqlserver-adapter-6.0.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:416 in the raw_select method. The log lambda returns:
=> #<ActiveRecord::Result:0x0000555a231ea0a0 @column_types={}, @columns=["name"], @hash_rows=nil, @rows=[["candidate_id"], ["rollup_name"]]>
When it should return those two column names individually. Is the activerecord-sqlserver-adapter repo a better place for this?
Backtrace: "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-sqlserver-adapter-6.0.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:450:in'
each'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-sqlserver-adapter-6.0.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:450:in
handle_to_names_and_values_dblib'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-sqlserver-adapter-6.0.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:441:inhandle_to_names_and_values'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-sqlserver-adapter-6.0.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:420:in
_raw_select'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-sqlserver-adapter-6.0.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:415:inblock in raw_select'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/connection_adapters/abstract_adapter.rb:722:in
block (2 levels) in log'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.2/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:inblock (2 levels) in synchronize'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.2/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in
handle_interrupt'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.2/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:inblock in synchronize'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.2/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in
handle_interrupt'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.2/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:insynchronize'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/connection_adapters/abstract_adapter.rb:721:in
block in log'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.3.2/lib/active_support/notifications/instrumenter.rb:24:ininstrument'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/connection_adapters/abstract_adapter.rb:712:in
log'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-sqlserver-adapter-6.0.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:415:inraw_select'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-sqlserver-adapter-6.0.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:304:in
sp_executesql'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-sqlserver-adapter-6.0.0/lib/active_record/connection_adapters/sqlserver/database_statements.rb:35:inexec_query'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:493:in
select_prepared'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:68:inselect_all'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:107:in
select_all'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/querying.rb:46:infind_by_sql'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/relation.rb:821:in
block in exec_queries'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/relation.rb:836:inblock in skip_query_cache_if_necessary'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:79:in
uncached'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/query_cache.rb:21:inuncached'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/relation/delegation.rb:107:in
public_send'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/relation/delegation.rb:107:inblock in method_missing'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/relation.rb:407:in
block in scoping'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/relation.rb:784:in_scoping'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/relation.rb:407:in
scoping'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/relation/delegation.rb:107:inmethod_missing'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/relation.rb:835:in
skip_query_cache_if_necessary'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/relation.rb:808:inexec_queries'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/relation.rb:626:in
load'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/relation.rb:250:inrecords'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/relation/batches.rb:224:in
block in in_batches'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/relation/batches.rb:222:inloop'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/relation/batches.rb:222:in
in_batches'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/relation/batches.rb:135:infind_in_batches'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/relation/batches.rb:69:in
find_each'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activerecord-6.0.3.2/lib/active_record/querying.rb:21:infind_each'", "/home/ubuntu/loxo/production/lib/tasks/imports/import_common.rb:275:in
reencode_klass!'", "/home/ubuntu/loxo/production/lib/tasks/imports/import_common.rb:268:inblock in reencode_klasses!'", "/home/ubuntu/loxo/production/lib/tasks/imports/import_common.rb:267:in
each'", "/home/ubuntu/loxo/production/lib/tasks/imports/import_common.rb:267:inreencode_klasses!'", "/home/ubuntu/loxo/production/lib/tasks/imports/pcrecruiter_6403/pcrecruiter.rake:17:in
block (2 levels) in <top (required)>'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:281:inblock in execute'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:281:in
each'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:281:inexecute'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:219:in
block in invoke_with_call_chain'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:199:insynchronize'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:199:in
invoke_with_call_chain'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/task.rb:188:ininvoke'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:160:in
invoke_task'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:116:inblock (2 levels) in top_level'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:116:in
each'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:116:inblock in top_level'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:125:in
run_with_threads'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:110:intop_level'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:83:in
block in run'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:186:instandard_exception_handling'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.1/lib/rake/application.rb:80:in
run'", "/home/ubuntu/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rake-13.0.1/exe/rake:27:in<top (required)>'", "/home/ubuntu/.rbenv/versions/2.7.0/bin/rake:23:in
load'", "/home/ubuntu/.rbenv/versions/2.7.0/bin/rake:23:in `