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: Resolve the extra typeIndexJoins for _avg aggregate #774

Merged
merged 4 commits into from
Sep 15, 2022

Conversation

shahzadlone
Copy link
Member

@shahzadlone shahzadlone commented Sep 4, 2022

Resolves #640

Description

  • Add limit check to tryGetTarget function.
  • Fix the equality check with filter to find the host.
  • Update the previously documented tests that had incorrect behavior.

More Info on the bug:

The host was not being found and kept getting added incorrectly, this is because reflect.DeepEqual Fails when you have a map where the key is pointer.

	a1 := "str"
	a2 := "str"
	a3 := map[*string]bool{&a1: true}
	a4 := map[*string]bool{&a2: true}
	fmt.Println(reflect.DeepEqual(a3, a4)) // False

In this case it was slightly more hidden because the key was an interface with an underlying pointer. Here is a more accurate example on what was happening (the last case represents what was happening):

type Key interface{ Get() any }
type GoodKey struct{ Name any }

func (g GoodKey) Get() any { return g.Name }

func main() {
	a := GoodKey{Name: "key"}            // {key}
	b := GoodKey{Name: "key"}            // {key}
	fmt.Println(reflect.DeepEqual(a, b)) // true

	ma := map[Key]any{a: "non-pointer"}    // map[{key}:non-pointer]
	mb := map[Key]any{b: "non-pointer"}    // map[{key}:non-pointer]
	fmt.Println(reflect.DeepEqual(ma, mb)) // true

	pa := &a                               // &{key}
	pb := &b                               // &{key}
	fmt.Println(reflect.DeepEqual(pa, pb)) // true

	mpa := map[Key]any{pa: "pointer"}        // map[0xc000014250:pointer]
	mpb := map[Key]any{pb: "pointer"}        // map[0xc000014260:pointer]
	fmt.Println(reflect.DeepEqual(mpa, mpb)) // false
}

Can run the above here: https://go.dev/play/p/bBvUubM8u_N

@shahzadlone shahzadlone added bug Something isn't working action/no-benchmark Skips the action that runs the benchmark. area/mapper Related to the mapper components area/planner Related to the planner system labels Sep 4, 2022
@shahzadlone shahzadlone added this to the DefraDB v0.3.1 milestone Sep 4, 2022
@shahzadlone shahzadlone self-assigned this Sep 4, 2022
@shahzadlone shahzadlone marked this pull request as draft September 4, 2022 06:45
@codecov
Copy link

codecov bot commented Sep 13, 2022

Codecov Report

Merging #774 (8f19fc5) into develop (b4d2d63) will increase coverage by 0.09%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #774      +/-   ##
===========================================
+ Coverage    59.17%   59.27%   +0.09%     
===========================================
  Files          153      153              
  Lines        16994    17035      +41     
===========================================
+ Hits         10057    10098      +41     
  Misses        6020     6020              
  Partials       917      917              
Impacted Files Coverage Δ
query/graphql/mapper/mapper.go 85.54% <100.00%> (+0.69%) ⬆️
query/graphql/mapper/targetable.go 66.66% <100.00%> (+12.82%) ⬆️
connor/lt.go 72.72% <0.00%> (-4.55%) ⬇️

@shahzadlone shahzadlone force-pushed the lone/fix/extra-type-joins branch 2 times, most recently from 2076e5d to 7f66c60 Compare September 13, 2022 10:18
@shahzadlone shahzadlone marked this pull request as ready for review September 13, 2022 11:38
@shahzadlone shahzadlone requested review from AndrewSisley and a team September 13, 2022 11:42
@@ -530,176 +438,6 @@ func TestExplainAverageQueryOnMultipleJoinedFieldWithFilter(t *testing.T) {
},
},
},
{
Copy link
Contributor

Choose a reason for hiding this comment

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

praise: Nice 😆

query/graphql/mapper/mapper.go Outdated Show resolved Hide resolved
Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

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

Looks much better than cloning and derefing and is easy to read, but added a couple of todos/question for you

query/graphql/mapper/mapper.go Outdated Show resolved Hide resolved
query/graphql/mapper/mapper.go Outdated Show resolved Hide resolved
query/graphql/mapper/mapper.go Outdated Show resolved Hide resolved
query/graphql/mapper/targetable.go Outdated Show resolved Hide resolved
@@ -9,4 +9,6 @@ type FilterKey interface {
// GetOperatorOrDefault returns either the operator that corresponds
// to this key, or the given default.
GetOperatorOrDefault(defaultOp string) string
// Equal returns true if other is structurally equal, otherwise returns false.
Equal(other FilterKey) bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice :) Was hoping you would do this

connor/key.go Outdated Show resolved Hide resolved
Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

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

Approved, looks good, but 3 more comments that should preferably be addressed first (particularly the one RE why you keep looping when you already know that it is not equal)

query/graphql/mapper/targetable.go Outdated Show resolved Hide resolved
query/graphql/mapper/mapper.go Outdated Show resolved Hide resolved
@shahzadlone
Copy link
Member Author

Approved, looks good, but 3 more comments that should preferably be addressed first (particularly the one RE why you keep looping when you already know that it is not equal)

Maybe there are some unpending comments, I only see 2 new comments + this one I am replying to.

Which comment are you referring to here: 'RE why you keep looping when you already know that it is not equal'?

@shahzadlone
Copy link
Member Author

Approved, looks good, but 3 more comments that should preferably be addressed first (particularly the one RE why you keep looping when you already know that it is not equal)

Maybe there are some unpending comments, I only see 2 new comments + this one I am replying to.

Which comment are you referring to here: 'RE why you keep looping when you already know that it is not equal'?

EDIT: I think I know which one you are talking about left a follow-up reply.

Copy link
Collaborator

@fredcarle fredcarle left a comment

Choose a reason for hiding this comment

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

Looking good. Just a few comments :)

query/graphql/mapper/mapper.go Outdated Show resolved Hide resolved
query/graphql/mapper/mapper.go Outdated Show resolved Hide resolved
query/graphql/mapper/mapper.go Outdated Show resolved Hide resolved
a dereferenced version of the filter conditions and also get rid of
reflect.DeepEqual() comparison.

- Adhere to code review.
@shahzadlone shahzadlone merged commit 0ad47d5 into develop Sep 15, 2022
@shahzadlone shahzadlone deleted the lone/fix/extra-type-joins branch September 15, 2022 18:16
shahzadlone added a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
…etwork#774)

- Resolves sourcenetwork#640

- Description:
* Add limit check to `tryGetTarget` function.
* Fix the equality check with the filter to find the host.
* Update the previously documented tests that had incorrect behavior.
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/mapper Related to the mapper components 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.

Average query with subType field creates unnecessary typeIndexJoins under parallelNode
3 participants