I'm interested in Postgres, but I suppose the answer may be universally the same. I'm curious what, if anything, is different between these two queries, where foo is a numeric (bigint) and bar is a string (varchar) and together they make up the primary key (foo, bar).
select * from my_table order by foo, bar for update
select * from my_table order by (foo, bar) for update
There is a difference in the explain plan (see below), but it's not obvious to me if it actually changes the lock order, which is what I'm really interested in. I'm battling some occassional deadlocks and the one thing I've noticed is inconsistent use between the two different sorting rules. Perhaps this could be the cause?
LockRows (cost=83.37..98.37 rows=1200 width=78)
-> Sort (cost=83.37..86.37 rows=1200 width=78)
Sort Key: (ROW(foo, bar))
-> Seq Scan on my_table (cost=0.00..22.00 rows=1200 width=78)
LockRows (cost=0.15..78.15 rows=1200 width=46)
-> Index Scan using my_table_pkey on my_table (cost=0.15..66.15 rows=1200 width=46)