crystal-pg
crystal-pg copied to clipboard
Are prepared statements supposed to bypass PARSE?
Maybe I'm doing something wrong here (or misunderstanding things) but this returns true:
puts "Prepared: #{db.prepared_statements?}"
I then ran this:
db.transaction do |trx|
e1 = Time.measure do
stmt = trx.connection.build("insert into junk(c1, c2, c3) values ($1, $2, $3)")
10.times do |i|
stmt.exec(i, ">" + i.to_s + "<", i & 2 == 0)
end
end
puts "e1 = #{e1}"
e2 = Time.measure do
10.times do |i|
trx.connection.exec("insert into junk(c1, c2, c3) values ($1, $2, $3)", i, ">" + i.to_s + "<", i & 2 == 0)
end
end
puts "e2 = #{e2}"
trx.rollback
end
I tailed the database log file and expected to see 1 parse followed by 10 sets of bind and execute with the first block, and 10 sets of parse, bind and execute with the second block. However, in both cases I see 10 sets of parse, bind and execute, so I'm wondering if I've misunderstood the purpose of Connection#build.
I noticed #97 so I'm wondering why the pg driver returns true for Connection#prepared_statements? ?
Thanks,
Steve
I'm also running in to this. Are prepared statements properly supported?
The entry point for prepared vs unprepared statement is at: https://github.com/will/crystal-pg/blob/master/src/pg/connection.cr#L20-L26 . They are all unprepared under the hood.
So this line should probably look more like PreparedStatement.new(self, query) or whatever?
Maybe. It depends on the underlying implementation or protocol. In mysql the binary and text protocol that are used for prepared or unprepared statements is very different. In sqlite all the statements are prepared. I don’t know about the internals of pg protocol.