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

Count optimization changes #811

Merged
merged 6 commits into from
Jan 19, 2024
Merged

Count optimization changes #811

merged 6 commits into from
Jan 19, 2024

Conversation

maheshrajamani
Copy link
Contributor

@maheshrajamani maheshrajamani commented Jan 19, 2024

What this PR does:
Count command changes to read primary key data and count in the client side. Number of keys read is controlled by configuration
Which issue(s) this PR fixes:
Fixes #809

Checklist

  • Changes manually tested
  • Automated Tests added/updated
  • Documentation added/updated
  • CLA Signed: DataStax CLA

@maheshrajamani maheshrajamani requested a review from a team as a code owner January 19, 2024 03:17
@maheshrajamani maheshrajamani self-assigned this Jan 19, 2024
CONFIGURATION.md Outdated Show resolved Hide resolved
@@ -100,6 +100,23 @@ public interface OperationsConfig {
@WithDefault("1000")
int maxVectorSearchLimit();

/**
* @return Maximum size of keys read from database to return count, Setting it to -1 will use
Copy link
Contributor

Choose a reason for hiding this comment

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

Maximum size -> Maximum number ?

@@ -38,16 +55,29 @@ private SimpleStatement buildSelectQuery() {
if (expressions != null && !expressions.isEmpty() && expressions.get(0) != null) {
collect = ExpressionBuilder.getExpressionValuesInOrder(expressions.get(0));
Copy link
Contributor

@tatu-at-datastax tatu-at-datastax Jan 19, 2024

Choose a reason for hiding this comment

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

I know this is existing unchanged code, but can expressions ever have more than 1 element? It seems that'd not be supported. Would it make sense to assert (throw exception) if more than one exists?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why this is done that way. I will create a issue to handle all expressions,

@@ -5,9 +5,13 @@
import java.util.Map;
import java.util.function.Supplier;

public record CountOperationPage(long count) implements Supplier<CommandResult> {
public record CountOperationPage(long count, boolean moreData) implements Supplier<CommandResult> {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can use moreData, but could also name it something like countIncomplete or hasMoreRows?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used it because DeleteMany and UpdateMany use this falg.

Copy link
Contributor

@tatu-at-datastax tatu-at-datastax left a comment

Choose a reason for hiding this comment

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

Looks good -- functionality fine, only suggestions are wrt naming and documentation/comments (to help whoever reads code).

The only substantial suggestion other than that is whether we should throw JsonApiException from failing query. That seems like it could be useful for debugging.

@maheshrajamani maheshrajamani merged commit bbf46e6 into main Jan 19, 2024
2 checks passed
@maheshrajamani maheshrajamani deleted the count-optimization branch January 19, 2024 20:44
@@ -335,7 +351,7 @@ public void withExistFalseOperator() {
.post(CollectionResource.BASE_PATH, namespaceName, collectionName)
.then()
.statusCode(200)
.body("status.count", is(4))
.body("status.count", is(5))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did this change? Doesn't seem like a perf optimization should change the result here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vkarpov15 Have inserted one more document for testing moreData flag. Because of the additional record count increased by 1 for the provided filter condition in this test case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Makes sense, thanks for clarifying.

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.

Count command optimization
3 participants