# Override query hostgroup

**URL:** <https://forums.percona.com/t/override-query-hostgroup/31755>\
**Category:** ProxySQL\
**Created:** [July 22, 2024, 3:04pm UTC](https://forums.percona.com/t/override-query-hostgroup/31755 "2024-07-22T15:04:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gtech1](https://avatars.discourse-cdn.com/v4/letter/g/5f8ce5/32.png) [@gtech1](https://forums.percona.com/u/gtech1)\
**Post date:** [July 22, 2024, 3:04pm UTC](https://forums.percona.com/t/override-query-hostgroup/31755/1 "2024-07-22T15:04:33Z")

</div>

I have an application that runs perfectly well on ProxySQL except in a few specific circumstances. I route all SELECT queries to the read hostgroup and that works very well.

The specific circumstances is when the application performs some internal clean-up and then it sets the connection mode to: SET sql\_mode=‘STRICT\_ALL\_TABLES,NO\_ZERO\_IN\_DATE,NO\_ZERO\_DATE,ERROR\_FOR\_DIVISION\_BY\_ZERO,NO\_ENGINE\_SUBSTITUTION’,time\_zone = ‘+00:00’,lc\_messages = ‘en\_US’

all queries from this connection should run in the write hostgroup, even the select queries, thus overriding my rule. Is there a way to do that ?

Right now this application mode errors out on a select query with: SQLSTATE[Y0000]: \<\>: 9006 ProxySQL Error: connection is locked to hostgroup 0 but trying to reach hostgroup 2 .

I’d rather not set `mysql-set_query_lock_on_hostgroup` to 0 since that introduces more issues.

This is on version 2.6.3

Any ideas ? Thank you

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [July 22, 2024, 4:21pm UTC](https://forums.percona.com/t/override-query-hostgroup/31755/2 "2024-07-22T16:21:39Z")

</div>

If you start an explicit transaction before executing this SET statement, then all queries inside the transaction will be routed to the writer, including SELECTs. ProxySQL does not break up transactions.

---

<div class="post-metadata">

**Author:** ![gtech1](https://avatars.discourse-cdn.com/v4/letter/g/5f8ce5/32.png) [@gtech1](https://forums.percona.com/u/gtech1)\
**Post date:** [July 22, 2024, 6:49pm UTC](https://forums.percona.com/t/override-query-hostgroup/31755/3 "2024-07-22T18:49:22Z")

</div>

Understood. Thank you. Is there no session locking to a certain hostgroup once the session has been restricted this way ? It would be equivalent to having a transaction I guess

mysql\> SET SESSION sql\_mode = ‘STRICT\_ALL\_TABLES,NO\_ZERO\_IN\_DATE,NO\_ZERO\_DATE,ERROR\_FOR\_DIVISION\_BY\_ZERO,NO\_ENGINE\_SUBSTITUTION’;  
Query OK, 0 rows affected (0.00 sec)

mysql\> SELECT u.id, u.displayName, u.recoveryHash, u.recoverySendAt, u.theme, u.files\_folder\_id, u.last\_password\_change, u.id AS `u.id`, p.password, p.userId AS `p.userId`  
 → FROM `core_user` `u`  
 → LEFT JOIN `core_auth_password` `p` ON  
 → u.id = p.userId  
 → WHERE  
 → `u`.`id` = ‘1’  
 → LIMIT 0,1;  
ERROR 9006 (Y0000): ProxySQL Error: connection is locked to hostgroup 0 but trying to reach hostgroup 2

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [July 22, 2024, 7:07pm UTC](https://forums.percona.com/t/override-query-hostgroup/31755/4 "2024-07-22T19:07:46Z")

</div>

Yes, there is session locking, which is what you are experiencing. `SET` statements tell ProxySQL to go to writer, but you have a rule that says ‘SELECTs go here’ and it won’t do that. You should explicitly `START TRANSACTION; SET SESSION ...; SELECT ..; COMMIT` and that should all be routed to the same connection on the writer.

---

<div class="post-metadata">

**Author:** ![gtech1](https://avatars.discourse-cdn.com/v4/letter/g/5f8ce5/32.png) [@gtech1](https://forums.percona.com/u/gtech1)\
**Post date:** [July 22, 2024, 7:18pm UTC](https://forums.percona.com/t/override-query-hostgroup/31755/5 "2024-07-22T19:18:26Z")

</div>

sorry, what I meant was to make the entire connection go to the writer hostgroup once the set command has been issued. Or you think that would break a lot of the intended usage of proxysql ?

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [July 22, 2024, 7:57pm UTC](https://forums.percona.com/t/override-query-hostgroup/31755/6 "2024-07-22T19:57:03Z")

</div>

> [@gtech1](#):
>
> what I meant was to make the entire connection go to the writer hostgroup once the set command has been issued

Yes, you can do that by forcing a transaction as I showed above.

If you simply do `SET ..; SELECT..` you will get the error you are experiencing because ProxySQL disabled multiplexing on ‘SET’ commands.

> **[Multiplexing - ProxySQL](https://proxysql.com/documentation/multiplexing/)**
>
> What is multiplexing?
> Multiplexing in ProxySQL is a feature that allows multiple frontend connections to re-use the same database backend connection. MySQL uses a "thread per connection" rather than a "thread pool" implementation. This results in a...

See the section on ’ Tuning multiplexing’ and you can create a rule that forces multiplexing even when SET sql\_mode is detected.

---

<div class="post-metadata">

**Author:** ![gtech1](https://avatars.discourse-cdn.com/v4/letter/g/5f8ce5/32.png) [@gtech1](https://forums.percona.com/u/gtech1)\
**Post date:** [July 23, 2024, 12:04am UTC](https://forums.percona.com/t/override-query-hostgroup/31755/7 "2024-07-23T00:04:59Z")

</div>

Thank you. It’s all good now. Much appreciated Matthew
