-
this link -> https://planetscale.com/docs/concepts/replicas said I can use SELECT on the replica using @replica and all the subsequent query would be using the replica database. But how do I know when I am using the replica or the primary one. For the example:
For this case I want to use the replica only until 2nd line and I want to use the primary on the 3rd one. Does the use@replica only affect for 1 sql script? or it also would affect all of my query afterwards? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
This applies to a whole session/connection. So with your example, it very much depends on how your application manages that, but if a single MySQL connection is used for all 3 queries, both of the select statements would use the replica. If a disconnect happened between, they would not. Variables and other state like that is bound to a MySQL connection. |
Beta Was this translation helpful? Give feedback.
Hello @esaputras,
Matt's comments above are 100% accurate as after the initial
use @replica;
from your first line the subsequent two queries would both occur against the replicas if the same connection was used afterward.Matt can correct me if I'm wrong here but in a quick test using our web console the following did appear to behave as expected so it may be another tip you can use to do what you described.
Should you want to switch back and forth within the same connection, you can probably do the following:
use @replica;
select * from table1;
use @primary;
(optionally, you may also simply runuse;
butuse @primary;
is more explicit)select * from table2;
And this would help to allow …