Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support parameter passing to foreign server #293

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adamf-db
Copy link

@adamf-db adamf-db commented Feb 16, 2024

This PR adds support for forwarding on parameters of prepared statements to MySQL, and adds a cache for same to support statement reuse.

For example, given:

PREPARE stmt2(varchar, varchar) AS SELECT "ycsb_key", "field1" from test.usertable16 WHERE "ycsb_key" = $1 AND "field1" = $2;
execute stmt2('user6578719', 'URxagQKtjthTPuimdkHxYDnjILIhMWcGVLYncvagEcJWgqtpQZeenCPJlywchyuhGLdDWTmqmibMoNEfDQqtgWoqcCOQBfTUPthu');

The execute call now uses:

SELECT `ycsb_key`, `field1` FROM `test`.`usertable16` WHERE ((`ycsb_key` = ?)) AND ((`field1` = ?))

Instead of a query using constant value. Sending on the parameters allows MySQL to cache & re-use the plan.

NOTE the Postgres setting plan_cache_mode should be set to force_generic_plan for this patch to have impact. Otherwise, Postgres may create a plan that replaces the parameters before handing the plan to the FDW, breaking the forwarding of the parameters to the foreign server.

In testing with go-ycsb I have seen an improvement in throughput and improved latency. This is largely due to the nature of the benchmark (lots of the same queries with parameters), but without this patch the same benchmark performs very poorly as the mysql side needs to rebuild the plan on each statement.

@surajkharage19
Copy link

Hi @adamf-db,

Thank you for PR.

I can see that you have made the code changes for the feature that you mentioned but test cases are missing.

can you please add the test cases as well so that we can go ahead and review this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants