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

Secondary index on relation panics when querying #2862

Closed
AndrewSisley opened this issue Jul 24, 2024 · 0 comments · Fixed by #2867
Closed

Secondary index on relation panics when querying #2862

AndrewSisley opened this issue Jul 24, 2024 · 0 comments · Fixed by #2867
Assignees
Labels
area/query Related to the query component bug Something isn't working
Milestone

Comments

@AndrewSisley
Copy link
Contributor

AndrewSisley commented Jul 24, 2024

The following test panics:

func TestQueryWithIndexOnManyToOne_IfFilterOnIndexedRelation_ShouldFilterWithExplain2(t *testing.T) {
	test := testUtils.TestCase{
		Actions: []any{
			testUtils.SchemaUpdate{
				Schema: `
					type User {
						name: String
						devices: [Device]
					}

					type Device {
						model: String
						owner: User @index
						manufacturer: Manufacturer @index
					}

					type Manufacturer {
						name: String
						devices: [Device]
					}
				`,
			},
			testUtils.CreateDoc{
				DocMap: map[string]any{
					"name": "John",
				},
			},
			testUtils.CreateDoc{
				CollectionID: 2,
				DocMap: map[string]any{
					"name": "foo",
				},
			},
			testUtils.CreateDoc{
				CollectionID: 1,
				DocMap: map[string]any{
					"model":        "MacBook Pro",
					"owner":        testUtils.NewDocIndex(0, 0),
					"manufacturer": testUtils.NewDocIndex(2, 0),
				},
			},
			testUtils.Request{
				Request: `query {
					User {
						devices {
							owner_id
							manufacturer_id
						}
					}
				}`,
				Results: []map[string]any{},
			},
		},
	}

	testUtils.ExecuteTestCase(t, test)
}
panic: runtime error: index out of range [1] with length 1
	panic: Unclosed iterator at time of Txn.Discard. [recovered]
	panic: Unclosed iterator at time of Txn.Discard.

goroutine 39 [running]:
testing.tRunner.func1.2({0x411f8e0, 0x53e8fd0})
	/usr/local/go/src/testing/testing.go:1545 +0x238
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1548 +0x397
panic({0x411f8e0?, 0x53e8fd0?})
	/usr/local/go/src/runtime/panic.go:914 +0x21f
github.com/sourcenetwork/badger/v4.(*Txn).Discard(...)
	/home/andy/go/pkg/mod/github.com/sourcenetwork/badger/v4@v4.2.1-0.20231113215945-a63444ca5276/txn.go:524
github.com/sourcenetwork/defradb/datastore/badger/v4.(*txn).discard(...)
	/home/andy/Projects/Source/defradb/datastore/badger/v4/datastore.go:780
github.com/sourcenetwork/defradb/datastore/badger/v4.(*txn).Discard(0x2df5ee9?, {0x7d829e8?, 0x473cb01?})
	/home/andy/Projects/Source/defradb/datastore/badger/v4/datastore.go:776 +0x125
github.com/sourcenetwork/defradb/datastore.(*txn).Discard(0xc0013bc300, {0x543a8e0?, 0xc00131d2f0?})
	/home/andy/Projects/Source/defradb/datastore/txn.go:125 +0x32
panic({0x46a31a0?, 0xc001b7e198?})
	/usr/local/go/src/runtime/panic.go:914 +0x21f
github.com/sourcenetwork/defradb/internal/db/fetcher.(*IndexFetcher).newIndexDataStoreKeyWithValues(0xc001e85880, {0xc001b821a0, 0x2, 0x20?})
	/home/andy/Projects/Source/defradb/internal/db/fetcher/indexer_iterators.go:530 +0xe9
github.com/sourcenetwork/defradb/internal/db/fetcher.(*IndexFetcher).newPrefixIndexIterator(0xc001e85880, {0xc001b86660, 0x2, 0x31313131?}, {0xc001b82180, 0x2, 0x2})
	/home/andy/Projects/Source/defradb/internal/db/fetcher/indexer_iterators.go:457 +0x1af
github.com/sourcenetwork/defradb/internal/db/fetcher.(*IndexFetcher).createIndexIterator(0xc001e85880)
	/home/andy/Projects/Source/defradb/internal/db/fetcher/indexer_iterators.go:561 +0x147
github.com/sourcenetwork/defradb/internal/db/fetcher.(*IndexFetcher).Init(0xc001e85880, {0x543a8e0, 0xc00131d2f0}, {0x0, {0x0, 0x0, {0x0, 0x0}, {0x0, 0x0}}}, ...)
	/home/andy/Projects/Source/defradb/internal/db/fetcher/indexer.go:95 +0x619
github.com/sourcenetwork/defradb/internal/lens.(*lensedFetcher).Init(0xc00112e7e0, {0x543a8e0?, 0xc00131d2f0}, {0x0, {0x0, 0x0, {0x0, 0x0}, {0x0, 0x0}}}, ...)
	/home/andy/Projects/Source/defradb/internal/lens/fetcher.go:115 +0xcad
github.com/sourcenetwork/defradb/internal/planner.(*scanNode).Init(0xc001aba540)
	/home/andy/Projects/Source/defradb/internal/planner/scan.go:65 +0x17e
github.com/sourcenetwork/defradb/internal/planner.(*multiScanNode).Init(0x13?)
	/home/andy/Projects/Source/defradb/internal/planner/scan.go:335 +0x16
github.com/sourcenetwork/defradb/internal/planner.(*invertibleTypeJoin).Init(0xc00795c000)
	/home/andy/Projects/Source/defradb/internal/planner/type_join.go:480 +0x48
github.com/sourcenetwork/defradb/internal/planner.(*typeIndexJoin).Init(0xc00794a0c0?)
	/home/andy/Projects/Source/defradb/internal/planner/type_join.go:110 +0x1c
github.com/sourcenetwork/defradb/internal/planner.(*parallelNode).Init.func1(...)
	/home/andy/Projects/Source/defradb/internal/planner/multi.go:83
github.com/sourcenetwork/defradb/internal/planner.(*parallelNode).applyToPlans(...)
	/home/andy/Projects/Source/defradb/internal/planner/multi.go:70
github.com/sourcenetwork/defradb/internal/planner.(*parallelNode).Init(0x1?)
	/home/andy/Projects/Source/defradb/internal/planner/multi.go:82 +0x51
github.com/sourcenetwork/defradb/internal/planner.(*selectNode).Init(0x1?)
	/home/andy/Projects/Source/defradb/internal/planner/select.go:138 +0x1c
github.com/sourcenetwork/defradb/internal/planner.(*selectTopNode).Init(0xc000f71128?)
	/home/andy/Projects/Source/defradb/internal/planner/select.go:66 +0x1c
github.com/sourcenetwork/defradb/internal/planner.(*primaryObjectsRetriever).collectDocs(0xc00795a101?, 0x0)
	/home/andy/Projects/Source/defradb/internal/planner/type_join.go:562 +0x3d
github.com/sourcenetwork/defradb/internal/planner.(*primaryObjectsRetriever).retrievePrimaryDocs(0xc00788a0c0)
	/home/andy/Projects/Source/defradb/internal/planner/type_join.go:596 +0x3dc
github.com/sourcenetwork/defradb/internal/planner.(*primaryObjectsRetriever).retrievePrimaryDocsReferencingSecondaryDoc(0xc00788a0c0)
	/home/andy/Projects/Source/defradb/internal/planner/type_join.go:536 +0x210
github.com/sourcenetwork/defradb/internal/planner.(*invertibleTypeJoin).fetchPrimaryDocsReferencingSecondaryDoc(0x0?)
	/home/andy/Projects/Source/defradb/internal/planner/type_join.go:655 +0xa7
github.com/sourcenetwork/defradb/internal/planner.(*invertibleTypeJoin).Next(0xc00795c2c0)
	/home/andy/Projects/Source/defradb/internal/planner/type_join.go:681 +0x119
github.com/sourcenetwork/defradb/internal/planner.(*typeIndexJoin).Next(0xc00788a2b0?)
	/home/andy/Projects/Source/defradb/internal/planner/type_join.go:124 +0x22
github.com/sourcenetwork/defradb/internal/planner.(*selectNode).Next(0xc001e8a000)
	/home/andy/Projects/Source/defradb/internal/planner/select.go:153 +0x3c
github.com/sourcenetwork/defradb/internal/planner.(*selectTopNode).Next(0xc000fdc0b0?)
	/home/andy/Projects/Source/defradb/internal/planner/select.go:70 +0x1c
github.com/sourcenetwork/defradb/internal/planner.(*Planner).executeRequest(0x0?, {0x4087d00?, 0xc001326a50?}, {0x5458408, 0xc007950be0})
	/home/andy/Projects/Source/defradb/internal/planner/planner.go:538 +0x4e
github.com/sourcenetwork/defradb/internal/planner.(*Planner).RunRequest(0x543a8e0?, {0x543a8e0, 0xc00131d2f0}, 0xc001326a50)
	/home/andy/Projects/Source/defradb/internal/planner/planner.go:593 +0x2c9
github.com/sourcenetwork/defradb/internal/db.(*db).execRequest(0xc001dd40c0, {0x543a8e0, 0xc00131d2f0}, {0x4b0a055, 0x5f})
	/home/andy/Projects/Source/defradb/internal/db/request.go:53 +0x426
github.com/sourcenetwork/defradb/internal/db.(*db).ExecRequest(0x0?, {0x543a8e0?, 0xc00131d230?}, {0x4b0a055, 0x5f})
	/home/andy/Projects/Source/defradb/internal/db/store.go:33 +0x1b3
github.com/sourcenetwork/defradb/tests/integration.executeRequest(0xc0012e7440, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x4b0a055, 0x5f}, {0x7ec4280, ...}, ...})
	/home/andy/Projects/Source/defradb/tests/integration/utils2.go:1686 +0x1d6
github.com/sourcenetwork/defradb/tests/integration.performAction(0xc0012e7440, 0x0?, {0x4702700?, 0xc001812d00?})
	/home/andy/Projects/Source/defradb/tests/integration/utils2.go:333 +0x8e5
github.com/sourcenetwork/defradb/tests/integration.executeTestCase({0x543a870?, 0x7ec4280}, {0x548cf18?, 0xc001d02b60?}, {0xc000b2b440, 0x3, 0x3}, {{0x0, 0x0}, {0xc00169ac80, ...}, ...}, ...)
	/home/andy/Projects/Source/defradb/tests/integration/utils2.go:226 +0xeab
github.com/sourcenetwork/defradb/tests/integration.ExecuteTestCase({0x548cf18?, 0xc001d02b60}, {{0x0, 0x0}, {0xc00169ac80, 0x5, 0x5}, {0x0, {0x0, 0x0, ...}}, ...})
	/home/andy/Projects/Source/defradb/tests/integration/utils2.go:180 +0x608
github.com/sourcenetwork/defradb/tests/integration/index.TestQueryWithIndexOnManyToOne_IfFilterOnIndexedRelation_ShouldFilterWithExplain2(0x0?)
	/home/andy/Projects/Source/defradb/tests/integration/index/query_with_relation_filter_test.go:969 +0x587
testing.tRunner(0xc001d02b60, 0x4da9a78)
	/usr/local/go/src/testing/testing.go:1595 +0xff
created by testing.(*T).Run in goroutine 1
	/usr/local/go/src/testing/testing.go:1648 +0x3ad

It does not panic if any of the query fields are omitted.

@AndrewSisley AndrewSisley added bug Something isn't working area/query Related to the query component labels Jul 24, 2024
@AndrewSisley AndrewSisley added this to the DefraDB v0.13 milestone Jul 24, 2024
@AndrewSisley AndrewSisley self-assigned this Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/query Related to the query component bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant