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

fix: Add a check to ensure limit is not 0 when evaluating query limit and offset #706

Merged
merged 5 commits into from
Aug 2, 2022

Conversation

fredcarle
Copy link
Collaborator

@fredcarle fredcarle commented Aug 2, 2022

Relevant issue(s)

Resolves #705
Resolves #620

Description

This PR solves a situation where setting an offset to the query without setting a limit would yield a single result.

Tasks

  • I made sure the code is well commented, particularly hard-to-understand areas.
  • I made sure the repository-held documentation is changed accordingly.
  • I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in tools/configs/chglog/config.yml).
  • I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ...

How has this been tested?

integration testing

Specify the platform(s) on which this was tested:

  • MacOS

@fredcarle fredcarle added action/no-benchmark Skips the action that runs the benchmark. area/planner Related to the planner system labels Aug 2, 2022
@fredcarle fredcarle added this to the DefraDB v0.3 milestone Aug 2, 2022
@fredcarle fredcarle requested a review from a team August 2, 2022 04:43
@fredcarle fredcarle self-assigned this Aug 2, 2022
@fredcarle fredcarle added the bug Something isn't working label Aug 2, 2022
@fredcarle
Copy link
Collaborator Author

@jsimnz the fix is a little different than what you suggested. Decided on not changing the node limit directly and rather just check that it's not 0. This avoids the large int64 in the explain response.

@jsimnz
Copy link
Member

jsimnz commented Aug 2, 2022

@jsimnz the fix is a little different than what you suggested. Decided on not changing the node limit directly and rather just check that it's not 0. This avoids the large int64 in the explain response.

makes sense

Copy link
Member

@jsimnz jsimnz left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 86 to 94
limitLabel: n.limit,
exp := map[string]interface{}{
offsetLabel: n.offset,
}, nil
}

if n.limit != 0 {
exp[limitLabel] = n.limit
}

return exp, nil
Copy link
Member

Choose a reason for hiding this comment

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

suggestion(blocking): I disagree with this change. Every implementation of Explain right now dumps a fixed number of attributes. n.limit attribute is the most important attribute in both the "limitNodes". Furthermore the current implementation of explain is also considered the v1(i.e. verbose=true) and if we want to have a different number of attributes depending on certain situations those need to be first thought out for every explain node and be handled in a verbose = false feature. Please revert this change.

Comment on lines 152 to 167
limitLabel: n.limit,
exp := map[string]interface{}{
offsetLabel: n.offset,
}, nil
}

if n.limit != 0 {
exp[limitLabel] = n.limit
}

return exp, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

suggestion(blocking): Similar comment as above.

@@ -138,7 +138,6 @@ func TestExplainQueryWithOnlyOffsetSpecified(t *testing.T) {
"explain": dataMap{
"selectTopNode": dataMap{
"hardLimitNode": dataMap{
"limit": int64(0),
Copy link
Member

Choose a reason for hiding this comment

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

suggestion(blocking): Following the above comments is an important attribute, please leave in.

@@ -528,7 +527,6 @@ func TestExplainQueryWithOnlyOffsetOnChild(t *testing.T) {
"subType": dataMap{
"selectTopNode": dataMap{
"hardLimitNode": dataMap{
"limit": int64(0),
Copy link
Member

Choose a reason for hiding this comment

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

suggestion(blocking): Following the above comments is an important attribute, please leave in.

Comment on lines 169 to 172
func TestQuerySimpleWithOffset(t *testing.T) {
tests := []testUtils.QueryTestCase{
{
Description: "Simple query with basic offset",
Copy link
Member

Choose a reason for hiding this comment

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

nitpick:

Suggested change
func TestQuerySimpleWithOffset(t *testing.T) {
tests := []testUtils.QueryTestCase{
{
Description: "Simple query with basic offset",
func TestQuerySimpleWithOnlyOffset(t *testing.T) {
tests := []testUtils.QueryTestCase{
{
Description: "Simple query with only offset",

},
},
{
Description: "Simple query with basic offset, more rows",
Copy link
Member

@shahzadlone shahzadlone Aug 2, 2022

Choose a reason for hiding this comment

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

nitpick: basic seems generic to me, perhaps use of only can signal that you are testing the case without limit.

Suggested change
Description: "Simple query with basic offset, more rows",
Description: "Simple query with only offset, more rows",

Copy link
Member

@shahzadlone shahzadlone left a comment

Choose a reason for hiding this comment

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

Thanks for the quick solution. Mainly concerned about the explain deleting the n.limit attribute in certain conditions mostly because current explain should dump attribute of interest as is.

@fredcarle fredcarle force-pushed the fredcarle/fix/I705-offset-with-no-limit branch from 5f2142c to 9d772b2 Compare August 2, 2022 17:57
Copy link
Member

@shahzadlone shahzadlone left a comment

Choose a reason for hiding this comment

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

LGTM!

Don't forget to update the PR Description:

This also removes the "limit": 0 object from the explain response when there is no limit.

@codecov
Copy link

codecov bot commented Aug 2, 2022

Codecov Report

Merging #706 (9d772b2) into develop (b17b020) will increase coverage by 0.02%.
The diff coverage is 81.25%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #706      +/-   ##
===========================================
+ Coverage    57.39%   57.42%   +0.02%     
===========================================
  Files          143      143              
  Lines        16398    16408      +10     
===========================================
+ Hits          9412     9422      +10     
  Misses        6102     6102              
  Partials       884      884              
Impacted Files Coverage Δ
query/graphql/planner/limit.go 90.69% <81.25%> (+1.22%) ⬆️

@fredcarle fredcarle merged commit 14c5b14 into develop Aug 2, 2022
@fredcarle fredcarle deleted the fredcarle/fix/I705-offset-with-no-limit branch August 2, 2022 18:09
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
… and offset (sourcenetwork#706)

Relevant issue(s)
Resolves sourcenetwork#705

Description
This PR solves a situation where setting an offset to the query without setting a limit would yield a single result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/no-benchmark Skips the action that runs the benchmark. area/planner Related to the planner system bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A query with an offset and no limit is returning only one result No tests for offset only
3 participants