rails-sqlserver / activerecord-sqlserver-adapter

SQL Server Adapter For Rails
MIT License
972 stars 558 forks source link

Explain query mechanism breaks for certain SQL statements #197

Closed dball closed 12 years ago

dball commented 12 years ago

I get a TinyTds error when some slow SQL hits the auto-explain plan mechanism. The slow SQL, mildly anonymized, reads:

["EXEC sp_executesql N'\n            select * from operation where opcode in (\n              select opcode from final_operation_txt where id in (\n              select taggable_id from taggings where\n              taggable_type = ''Variation'' AND\n              tag_id IN ( \n                select tag_id from taggings where\n                taggable_type = ''Thing'' and\n                taggable_id in ( \n                  select id from things where serial = N''1234567890''\n              ))\n            ) AND opcode in (\n              select trigger_operations.opcode FROM \n              trigger_operations, triggers WHERE\n              trigger_operations.trigger_id = triggers.id AND\n              triggers.event = ''create''\n            ))'", []]]

The unprepared queries resolve to:

[["'1234567890'", []]]

I'll boil this down to a failing test case and see about a patch.

metaskills commented 12 years ago

Check out the README on explain and let me know what you want to do.

dball commented 12 years ago

Thanks, I obviously failed to note that in the README. I'll re-open if I manage to make the failing test pass :)