Skip to content

[CASSANDRA-21637][trunk] Avoid double chunk read for BTI small partitions during a select query execution - #5098

Open
netudima wants to merge 2 commits into
apache:trunkfrom
netudima:CASSANDRA-21637-trunk
Open

[CASSANDRA-21637][trunk] Avoid double chunk read for BTI small partitions during a select query execution#5098
netudima wants to merge 2 commits into
apache:trunkfrom
netudima:CASSANDRA-21637-trunk

Conversation

@netudima

@netudima netudima commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

* iterator has to start. {@link #dataInput} lets that reader be reused instead of closed, so the iterator does
* not have to open the same position again; on a compressed table that would decompress and checksum the same
* chunk twice. It is null whenever there is nothing to reuse, and when it is not null the caller owns it and
* must close it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you also explain why the generic getPosition path does not need this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep, I've extended the comment

static final ExactPosition NOT_FOUND = new ExactPosition(null, null);

final TrieIndexEntry entry;
final FileDataInput dataInput;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm happy to accept this, but it does feel a bit risky to return an opened reader here.

Have you considered an option to carry a "query workset" of a kind with an operation, something that is closeable, opened in a try block by the caller, or by an upper-level task such as a query, and passed as an argument to this and other methods so that they can reuse readers and leave the closing to that workset object?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes, I was thinking about it but it looks for me a way too complicated: The reader is closed only once we've finished reading, so I have to propagate this context through many calls up to a high level, like:
org.apache.cassandra.db.rows.UnfilteredSource#rowIterator (which is invoked in several places, so it means I have to do try logic in all such places to avoid potential leaks).
org.apache.cassandra.db.SinglePartitionReadCommand#queryMemtableAndDisk (again many places this method is invoked by, same story)

So, for me it looks like there are more risks to make a mistake in such large refactoring vs the current limited change with to attaching to SSTableIterator lifecycle (what we did in some cases already)..

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