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

Add caution about using explicit PREPARE/EXECUTE call #25532

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sudhanshu456
Copy link
Contributor

@netlify /stable/develop/best-practices-ysql/#re-use-query-plans-with-prepared-statements

@sudhanshu456 sudhanshu456 added the area/documentation Documentation needed label Jan 8, 2025
@sudhanshu456 sudhanshu456 requested a review from premkumr January 8, 2025 13:31
@sudhanshu456 sudhanshu456 self-assigned this Jan 8, 2025
Copy link

netlify bot commented Jan 8, 2025

Deploy Preview for infallible-bardeen-164bc9 ready!

Name Link
🔨 Latest commit cf7bc51
🔍 Latest deploy log https://app.netlify.com/sites/infallible-bardeen-164bc9/deploys/6783ff96e61d9c00088a3787
😎 Deploy Preview https://deploy-preview-25532--infallible-bardeen-164bc9.netlify.app/stable/develop/best-practices-ysql/#re-use-query-plans-with-prepared-statements
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@sudhanshu456 sudhanshu456 requested a review from ddhodge January 8, 2025 14:07
docs/content/stable/develop/best-practices-ysql.md Outdated Show resolved Hide resolved
docs/content/stable/develop/best-practices-ysql.md Outdated Show resolved Hide resolved
docs/content/stable/develop/best-practices-ysql.md Outdated Show resolved Hide resolved
When using server-side pooling, avoid explicit `PREPARE`/`EXECUTE` calls and use protocol-level prepared statements instead. Explicit prepare/execute calls can make connections sticky, preventing you from utilizing the benefits of the connection manager or server-side pooling.

For example, with the NPGSQL driver, add the following to your connection string:
`Max Auto Prepare=100;Auto Prepare Min Usages=5;`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this a proper code block. no period.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can add the consult your driver documentation bit


When using server-side pooling, avoid explicit `PREPARE`/`EXECUTE` calls and use protocol-level prepared statements instead. Explicit prepare/execute calls can make connections sticky, preventing you from utilizing the benefits of the connection manager or server-side pooling.

For example, with the NPGSQL driver, add the following to your connection string:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? What does this do? I don't understand the link between not using explicit PREPARE and doing this.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"For protocol level prepared statements the location of phase type (prepare/bind/execute), ppstmt name and query is fixed and known to the odyssey. So odyssey is easily able to identify and modify the ppstmt name or prepare a query on the connection. But this is not true in case we want to use a PREPARE query (by either protocol)."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand the link with setting Max Auto Prepare and Auto Prepare Min Usages in the connections string. What do these options do/how do they help.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markpyb Does every driver have some equivalent setting to turn on prepared statements? So would something like this work -

"Depending on your driver, you may have to set some parameters to leverage prepared statements. For example, Npgsql supports automatic preparation using the Max Auto Prepare and Auto Prepare Min Usages connection parameters, which you add to your connection string as follows:

Max Auto Prepare=100;Auto Prepare Min Usages=5;

Consult your driver documentation."

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ddhodge yes every driver will have a different way to do it (if they support it) yes consult your driver documentation is good

@premkumr premkumr requested a review from markpyb January 10, 2025 17:16
@markpyb
Copy link

markpyb commented Jan 11, 2025

the information is correct

@markpyb
Copy link

markpyb commented Jan 11, 2025

it looks like i cant see the preview version until @ddhodge suggestions are commited

Copy link
Contributor

@premkumr premkumr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@markpyb markpyb marked this pull request as ready for review January 15, 2025 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/documentation Documentation needed
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

4 participants