distribute_reads not query from replica when query has bracket
icecold21 opened this issue · comments
Jonathan Wylliem commented
Hi Ankane, great gem btw,
I was wondering why query which has bracket arounds it goes to primary instead of replica.
These are code to repro the issue:
Query to replica
distribute_reads do
ActiveRecord::Base.connection.execute("SELECT 1")
end
Query to primary
distribute_reads do
ActiveRecord::Base.connection.execute("(SELECT 1)")
end
Andrew Kane commented
Hey @icecold21, Makara uses regular expressions to determine which queries can go to replicas. You can force the query to use a replica with distribute_reads(replica: true)
.
Jonathan Wylliem commented
Hi @ankane, thanks for the answer. I'll go ahead and close this issue.