-
Notifications
You must be signed in to change notification settings - Fork 1
fix(arcadedb): work around index-scan datetime comparison bug (3 code paths) #3
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -96,6 +96,25 @@ async def retrieve_episodes( | |||||
| except NotImplementedError: | ||||||
| pass | ||||||
|
|
||||||
| # ArcadeDB stores a native datetime write as a zone-less ChronoLocalDateTime | ||||||
| # but decodes an incoming native datetime parameter as a zone-aware | ||||||
| # OffsetDateTime -- comparing them directly raises a ClassCastException at | ||||||
| # the engine level (confirmed: reproducible whenever a range index on the | ||||||
| # property was created before any data existed, which is exactly what | ||||||
| # build_indices_and_constraints() always does). Wrapping both sides in | ||||||
| # datetime(...) sidesteps it; scoped to ARCADEDB only so the other | ||||||
| # providers' generated Cypher is untouched. | ||||||
| valid_at_where = ( | ||||||
| 'WHERE datetime(e.valid_at) <= datetime($reference_time)' | ||||||
| if driver.provider == GraphProvider.ARCADEDB | ||||||
| else 'WHERE e.valid_at <= $reference_time' | ||||||
| ) | ||||||
| valid_at_order = ( | ||||||
| 'ORDER BY datetime(e.valid_at) DESC' | ||||||
| if driver.provider == GraphProvider.ARCADEDB | ||||||
| else 'ORDER BY e.valid_at DESC' | ||||||
| ) | ||||||
|
|
||||||
| # If saga is provided, retrieve episodes from that saga only | ||||||
| if saga is not None: | ||||||
| group_id = group_ids[0] if group_ids else None | ||||||
|
|
@@ -104,7 +123,7 @@ async def retrieve_episodes( | |||||
| records, _, _ = await driver.execute_query( | ||||||
| f""" | ||||||
| MATCH (s:Saga {{name: $saga_name, group_id: $group_id}})-[:HAS_EPISODE]->(e:Episodic) | ||||||
| WHERE e.valid_at <= $reference_time | ||||||
| {valid_at_where} | ||||||
| {source_filter} | ||||||
| RETURN | ||||||
| """ | ||||||
|
|
@@ -113,8 +132,8 @@ async def retrieve_episodes( | |||||
| if driver.provider == GraphProvider.NEPTUNE | ||||||
| else EPISODIC_NODE_RETURN | ||||||
| ) | ||||||
| + """ | ||||||
| ORDER BY e.valid_at DESC | ||||||
| + f""" | ||||||
| {valid_at_order} | ||||||
| LIMIT $num_episodes | ||||||
| """, | ||||||
| saga_name=saga, | ||||||
|
|
@@ -138,9 +157,9 @@ async def retrieve_episodes( | |||||
| query_params['source'] = source.name | ||||||
|
|
||||||
| query: LiteralString = ( | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||
| """ | ||||||
| f""" | ||||||
| MATCH (e:Episodic) | ||||||
| WHERE e.valid_at <= $reference_time | ||||||
| {valid_at_where} | ||||||
| """ | ||||||
| + query_filter | ||||||
| + """ | ||||||
|
|
@@ -151,8 +170,8 @@ async def retrieve_episodes( | |||||
| if driver.provider == GraphProvider.NEPTUNE | ||||||
| else EPISODIC_NODE_RETURN | ||||||
| ) | ||||||
| + """ | ||||||
| ORDER BY e.valid_at DESC | ||||||
| + f""" | ||||||
| {valid_at_order} | ||||||
| LIMIT $num_episodes | ||||||
| """ | ||||||
| ) | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrapping the indexed property (
value_name) in thedatetime()function makes the query non-sargable. This means ArcadeDB's query planner will not be able to utilize the range index on these properties, potentially falling back to full scans and causing performance degradation on larger datasets. While this is a necessary workaround for the upstream engine bug (arcadedb#5008), please ensure there is a tracking issue or TODO to remove this workaround once the upstream fix is released.