trinodb / trino-go-client

Go client for Trino
Apache License 2.0
131 stars 60 forks source link

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

Open NachoNievaG opened 4 months ago

NachoNievaG commented 4 months ago

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 commented 3 months ago

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 commented 3 months ago

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!