Hi Jeremy,

I recently came accross these additional transactions when profiling our 
app. Would you be open to a PR which removes the transactions when they're 
not needed (when the group of inserts is a single statement)?

Cheers,

Daniel

On Tuesday, 5 February 2019 at 02:03:26 UTC+11 Maciek Mensfeld wrote:

> This is my temporary patch for that:
>
> module Patches
>   module SequelTransaction
>     DUMMY_TRANSACTION = ->(_, &block) { block.call }.freeze
>
>     def _import(columns, values, opts)
>       trans_opts = Hash[opts].merge!(server: @opts[:server])
>       trans = trans_opts.fetch(:transaction) { true }
>
>       trans_meth = trans ? @db.method(:transaction) : DUMMY_TRANSCATION
>
>       if opts[:return] == :primary_key
>         trans_meth.call(trans_opts){ values.map { |v| insert(columns, v) } 
> }
>       else
>         stmts = multi_insert_sql(columns, values)
>         trans_meth.call(trans_opts){ stmts.each { |st| execute_dui(st) } }
>       end
>     end
>   end
> end
>
> Sequel::Dataset.prepend(Patches::SequelTransaction)
>
>
>
>
> W dniu środa, 30 stycznia 2019 23:06:52 UTC+1 użytkownik Jeremy Evans 
> napisał:
>>
>> On Wednesday, January 30, 2019 at 12:50:43 PM UTC-8, Nikita Shilnikov 
>> wrote:
>>>
>>> Hello,
>>>
>>> It seems to me starting a new transaction in PG isn't necessary since it 
>>> will be executed as a single SQL statement 
>>> https://github.com/jeremyevans/sequel/blob/bd1e06f8b16c7311080c699e85080648ff14e602/lib/sequel/adapters/shared/postgres.rb#L1732
>>>  Is 
>>> it something to improve?
>>>
>>
>> Dataset#multi_insert / #import could potentially not use an transaction 
>> if only a single query was required.  However, transactions are currently 
>> used for all cases, and all options given are currently passed to 
>> Database#transaction.  I think the best way to skip a transaction in a 
>> backwards compatible manner would be to add a new option explicitly for 
>> that approach.
>>
>> Note that this isn't a PostgreSQL-specific issue, this applies to all 
>> adapters.
>>
>> Thanks,
>> Jeremy
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/e535c7c6-374d-4c00-9e4b-66a32f4f54e5n%40googlegroups.com.

Reply via email to