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

How to set a custom name to prepared statements, in different connections #118

Closed
NachoNievaG opened this issue May 17, 2024 · 3 comments · Fixed by #128
Closed

How to set a custom name to prepared statements, in different connections #118

NachoNievaG opened this issue May 17, 2024 · 3 comments · Fixed by #128

Comments

@NachoNievaG
Copy link

NachoNievaG commented May 17, 2024

I'm trying to name queries differently to avoid the generic
EXECUTE _trino_go USING 4
and get some context (at least in names).
EXECUTE total_customers_transactions USING 4
Is there a way to achieve this using the lib via ExecContext() o QueryRowContext()?

I feel like I'm missing something.
Thank you in advanced!

@nineinchnick
Copy link
Member

I don't think that's possible. It's a bit obvious, but please describe why do you need it - it'll help to discuss potential solutions.
Prepared statements are not that useful in Trino, the server doesn't keep any state for them, and the query text is always sent in the first request.

We can consider implementing EXECUTE IMMEDIATE to avoid one additional roundtrip, and you'll be able to see the query text in logs.

@NachoNievaG
Copy link
Author

Originally I could manage to handle troubleshoot without any specific query naming, but in recent scenarios my query volume execution grew to a scale that is pretty difficult to follow without any query naming to identify the exec in the WebUI. So having a way to identify at first glance with the last queries executed would be an improvement.
I forked a version that uses a context.Context value set in the query invoke, tested it out just to have a key name in prepared statements and it worked fairly well.
And got from this in the web UI:
image
To this:
image

But as you mentioned, Execute Immediate makes sense to, yet sounds quite complex for fairly "low" benefits.
Let me know if i can provide you with more context!

@nineinchnick
Copy link
Member

@NachoNievaG try setting explicitPrepare to false in the connection string or the config struct. This will switch the driver to use EXECUTE IMMEDIATE with the full query text visible in query history. If that doesn't solve your problem, feel free to reopen the issue.

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

Successfully merging a pull request may close this issue.

2 participants