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 indexes when join is needed #255

Merged
merged 3 commits into from
Mar 23, 2024
Merged

Fix indexes when join is needed #255

merged 3 commits into from
Mar 23, 2024

Conversation

mateusvmv
Copy link
Contributor

Fixes #254
Fixed the first query, with the correct binding of "a" to "**2", where it would previously bind "**1" (which is bound to b) to "**2".

 stratum | rule_idx | rule | atom_idx | op                   | ref         | joins_on    | filters/expr | out_relation 
---------+----------+------+----------+----------------------+-------------+-------------+--------------+-------------------
 0       | 0        | "?"  | 6        | "load_stored"        | ":source"   | null        | []           | ["x", "b"] 
 0       | 0        | "?"  | 5        | "load_stored"        | ":target:b" | null        | []           | ["**1", "**2"] 
 0       | 0        | "?"  | 4        | "stored_prefix_join" | null        | {"b":"**1"} | null         | ["b", "**2"] 
 0       | 0        | "?"  | 3        | "load_stored"        | ":target"   | null        | []           | ["a", "c", "**0"] 
 0       | 0        | "?"  | 2        | "stored_prefix_join" | null        | {"**2":"a"} | null         | ["b", "a", "c"] 
 0       | 0        | "?"  | 1        | "reorder"            | null        | null        | null         | ["a", "b", "c"] 
 0       | 0        | "?"  | 0        | "out"                | null        | null        | null         | ["a", "b", "c"] 

Fixed the second query,with the introduction of the filter, where it would previously ignore the bindings not present in the index.

 stratum | rule_idx | rule | atom_idx | op                   | ref      | joins_on     | filters/expr    | out_relation 
---------+----------+------+----------+----------------------+----------+--------------+-----------------+---------------------------
 0       | 0        | "?"  | 10       | "load_stored"        | ":rel"   | null         | []              | ["~1", "a1", "a2"] 
 0       | 0        | "?"  | 9        | "load_stored"        | ":rel:a" | null         | []              | ["**1", "**2"] 
 0       | 0        | "?"  | 8        | "stored_prefix_join" | null     | {"a2":"**1"} | null            | ["a1", "a2", "**2"] 
 0       | 0        | "?"  | 7        | "load_stored"        | ":rel"   | null         | []              | ["~2", "**0", "a3"] 
 0       | 0        | "?"  | 6        | "stored_prefix_join" | null     | {"**2":"~2"} | null            | ["a1", "a2", "a3"] 
 0       | 0        | "?"  | 5        | "load_stored"        | ":rel:a" | null         | []              | ["**5", "**6"] 
 0       | 0        | "?"  | 4        | "stored_prefix_join" | null     | {"a3":"**5"} | null            | ["a1", "a2", "a3", "**6"] 
 0       | 0        | "?"  | 3        | "load_stored"        | ":rel"   | null         | []              | ["~3", "**3", "**4"] 
 0       | 0        | "?"  | 2        | "stored_prefix_join" | null     | {"**6":"~3"} | null            | ["a1", "a2", "a3", "**4"] 
 0       | 0        | "?"  | 1        | "filter"             | null     | null         | ["eq(a1, **4)"] | ["a1", "a2", "a3"] 
 0       | 0        | "?"  | 0        | "out"                | null     | null         | null            | ["a1", "a2", "a3"] 

This makes the use of index, when not all fields are available in the index relation, compile down to:

  1. A load on the index
  2. A join of the index to the original relation
  3. A filter on the bindings that weren't present in the index

@zh217 zh217 merged commit 51581fb into cozodb:main Mar 23, 2024
1 check passed
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.

Wrong fields being used on index
2 participants