ryscheng / sql-proxy-rs

Programmable MariaDB/Postgres Proxy for Rust
Apache License 2.0
17 stars 11 forks source link

Is it possible to transform one packet from client to many to server? #26

Open tbicr opened 1 month ago

tbicr commented 1 month ago

I want to modify queries and instead of UPDATE test SET field=0 spawn few packets as UPDATE test SET field=0 WHERE 0 < id AND id <= 10000, UPDATE test SET field=0 WHERE 10000 < id AND id <= 20000 and etc. It's perfectly working when I use 1 to 1 packet transformation, but not for 1 to many.

Now as I understand sql-proxy-rs is not have any synchronization between read and write. But in postgres for example packet that comes before ReadyForQuery response will not be proceeded.

I wonder if you can you hint what is best way to solve this issue?

ryscheng commented 1 month ago

Cool! I hadn't really designed for this when I made it years ago. The crate probably needs some serious updating. At first glance we probably need to update the packet_handler to support this 1-to-many idea, then plumb backwards through the pipe. Let me know if you make any progress!

tbicr commented 1 month ago

I did few things mostly in pipeline and handler:

it works fine with postgres server, however it have few issues:

ryscheng commented 1 month ago

That makes sense, Im not sure how the client handles extra packets. Probably need to read more of the spec to see if theres a compliant way to do this