Skip to content

Fix unnecessary cancel requests #136

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

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

Conversation

Flgado
Copy link
Member

@Flgado Flgado commented Mar 3, 2025

Overview

This PR fixes unnecessary delete requests when the query is already finished.

Explanation

This change addresses Issue #102

  • When using QueryRow followed by a Scan, the Trino driver first calls the Next method and then the Close method. The Close method triggers a delete request to cancel the query, even when the query has already completed.
  • My initial approach was to use nextUri in the Close method instead of directly calling /v1/query/queryId, as suggested in the documentation and implemented by other drivers. However, to make this work, I needed to always update rows.nextUri inside the fetch method, as it was previously retaining only the first URI set here. Despite these changes, the issue persisted.
  • To resolve this, I modified the Next method so that when all rows have been read, it fetches the next set of rows. This works because our fetch method, along with the running Goroutines, follows nextUri until data is retrieved.
    • For QueryRow, this ensures that when the query reaches the finished state with no more data, nextUri is cleared, preventing an unnecessary request on Close().
    • For QueryContext, this is also fine because it fetches the next batch of data, ensuring that additional data (if available) is retrieved correctly.

Copy link

cla-bot bot commented Mar 3, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

Copy link

cla-bot bot commented Mar 3, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@nineinchnick
Copy link
Member

@cla-bot check

Copy link

cla-bot bot commented Mar 13, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

Copy link

cla-bot bot commented Mar 13, 2025

The cla-bot has been summoned, and re-checked this pull request!

Copy link

cla-bot bot commented Mar 15, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@Flgado
Copy link
Member Author

Flgado commented Mar 15, 2025

@nineinchnick add a need unit test. I think it make sense

@nineinchnick
Copy link
Member

@cla-bot check

@cla-bot cla-bot bot added the cla-signed label Apr 14, 2025
Copy link

cla-bot bot commented Apr 14, 2025

The cla-bot has been summoned, and re-checked this pull request!

qr.nextURI = ""
return nil

if qr.nextURI != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Reverse this condition and do an early return to avoid indenting the remaining code.

for i, v := range qr.coltype {
if i > len(dest)-1 {

row := qr.data[qr.rowindex]
Copy link
Member

Choose a reason for hiding this comment

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

Move any refactor not directly related to the issue this PR fixes to a separate commit.

qr.rowindex++

// Prefetch next set of rows
Copy link
Member

Choose a reason for hiding this comment

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

Useless comment - it explains the what, which is pretty obvious, but not the why, which is not. Why do we need to do this? If the user doesn't request any more data, we'll waste resources on one round-trip.

Can we do this only when cancelling the query?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have to rethink this PR. Now that I'm more familiar with the project, we can't approach it this way—it's a bit of a mess.
I'll work on it. Thanks!

@@ -1973,3 +1973,198 @@ func TestForwardAuthorizationHeader(t *testing.T) {

assert.NoError(t, db.Close())
}

func TestPagination(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you come up with a better name? I'm not sure what this test is for.

}

if r.URL.Path == "/v1/statement/20210817_140827_00000_arvdv/1" {
if buf2 == nil {
Copy link
Member

Choose a reason for hiding this comment

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

Why are separate buffers needed here? Can we initialize them early, and remove this condition?

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

Successfully merging this pull request may close these issues.

2 participants