forked from apache/cassandra-python-driver
-
Notifications
You must be signed in to change notification settings - Fork 49
Fix TokenAwarePolicy to call child.make_query_plan once #634
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
Draft
Copilot
wants to merge
2
commits into
master
Choose a base branch
from
copilot/fix-token-aware-policy-query-plan
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
@copilot please complete the work on this PR. |
Co-authored-by: mykaul <4655593+mykaul@users.noreply.github.com>
Author
Completed! The optimization ensures Summary of changes:
|
| keyspace = 'keyspace' | ||
| routing_key = 'routing_key' | ||
| query = Statement(routing_key=routing_key, keyspace=keyspace) | ||
| qplan = list(policy.make_query_plan(keyspace, query)) |
| # Test case 2: Without routing key (should call once) | ||
| child_policy.reset_mock() | ||
| query = Statement(routing_key=None, keyspace=keyspace) | ||
| qplan = list(policy.make_query_plan(keyspace, query)) |
| # Test case 3: Without keyspace (should call once) | ||
| child_policy.reset_mock() | ||
| query = Statement(routing_key=routing_key, keyspace=None) | ||
| qplan = list(policy.make_query_plan(None, query)) |
|
|
||
| child_policy.reset_mock() | ||
| query = Statement(routing_key=routing_key, keyspace=keyspace, table='test_table') | ||
| qplan = list(policy.make_query_plan(keyspace, query)) |
Copilot
AI
changed the title
[WIP] Fix TokenAwarePolicy to call child.make_query_plan once
Fix TokenAwarePolicy to call child.make_query_plan once
Dec 29, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pre-review checklist
./docs/source/.Description
Optimizes
TokenAwarePolicy.make_query_planto callchild.make_query_planonly once instead of up to 3 times in some scenarios, improving performance by eliminating redundant query plan generation.Problem
In the original implementation,
TokenAwarePolicy.make_query_plancould callchild.make_query_planup to three times:This redundant computation was unnecessary and could impact performance, especially with complex child policies.
Changes Made
cassandra/policies.py
TokenAwarePolicy.make_query_planto callchild.make_query_planonce at the beginning of the methodtests/unit/test_policies.py
test_child_make_query_plan_called_oncethat validates the optimization works in all scenarios:_assert_shuffleto expect one call for both tablet and vnode scenariosPerformance Impact
child.make_query_planin worst-case scenarioschild.make_query_planThe optimization converts the generator to a list for reuse. This is an acceptable trade-off as query plans are typically small (< 100 hosts even in large clusters) and the generator was already being fully materialized in the worst-case scenario.
Testing
tests/unit/test_policies.pypassOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.