Skip to content

Comments

Optimize queries to improve the query speed#504

Closed
aditya1702 wants to merge 83 commits intoremove-filteringfrom
query-optimize
Closed

Optimize queries to improve the query speed#504
aditya1702 wants to merge 83 commits intoremove-filteringfrom
query-optimize

Conversation

@aditya1702
Copy link
Contributor

What

[TODO: Short statement about what is changing.]

Why

[TODO: Why this change is being made. Include any context required to understand the why.]

Known limitations

[TODO or N/A]

Issue that this PR addresses

[TODO: Attach the link to the GitHub issue or task. Include the priority of the task here in addition to the link.]

Checklist

PR Structure

  • It is not possible to break this PR down into smaller PRs.
  • This PR does not mix refactoring changes with feature changes.
  • This PR's title starts with name of package that is most changed in the PR, or all if the changes are broad or impact many packages.

Thoroughness

  • This PR adds tests for the new functionality or fixes.
  • All updated queries have been tested (refer to this check if the data set returned by the updated query is expected to be same as the original one).

Release

  • This is not a breaking change.
  • This is ready to be tested in development.
  • The new functionality is gated with a feature flag if this is not ready for production.

… tests)

Bring in BYTEA type definitions, indexer changes, GraphQL schema/resolver
updates, processor changes, and test files from opxdr-bytea-2 branch.
These files had no modifications on the timescale branch.
…hemas

Change hash, account_id, operation_xdr, and address columns from TEXT
to BYTEA type while preserving all TimescaleDB hypertable configuration,
composite primary keys, and chunk settings.
… statechanges)

Convert hash, account_id, operation_xdr, and address columns from TEXT
to BYTEA in BatchInsert, BatchCopy, and query methods. Uses HashBytea,
AddressBytea, and pgtypeBytesFromNullAddressBytea for type conversions.
Preserves TimescaleDB junction table patterns (ledger_created_at columns,
composite primary keys, parameter numbering).
Adopt BYTEA types (HashBytea, AddressBytea, XDRBytea, NullAddressBytea)
in test data while preserving TimescaleDB-specific patterns:
- Keep ledger_created_at in junction table INSERTs
- Use generic "duplicate key value violates unique constraint" assertions
  (TimescaleDB chunk-based constraint names differ from standard PG)
- Keep 5-value return from processLedgersInBatch (includes startTime/endTime)
Rename inner err to addrErr in address BYTEA conversion loops to avoid
shadowing the outer err variable from pgx.CopyFrom.
Add optional since: Time and until: Time parameters to transactions,
operations, and stateChanges fields on the Account type. These enable
TimescaleDB chunk pruning on the ledger_created_at hypertable partition
column for significant query performance improvements.
gqlgen automatically updated resolver signatures to include
since *time.Time and until *time.Time parameters.
Shared helper for appending ledger_created_at >= / <= conditions to
query builders. Accepts a column name parameter for table-qualified
columns in CTEs. Used by all three BatchGetByAccountAddress methods.
Add *TimeRange parameter to transactions, operations, and state changes
BatchGetByAccountAddress. Inserts ledger_created_at >= / <= conditions
inside the MATERIALIZED CTE (transactions/operations) or after the
account_id WHERE clause (state changes) for early chunk pruning.
Add buildTimeRange helper that validates since <= until and constructs
a *data.TimeRange. All three account field resolvers (Transactions,
Operations, StateChanges) now build and pass time range to the data layer.
Update GetAccountTransactions, GetAccountOperations, and
GetAccountStateChanges client methods with since/until *time.Time
parameters. Update corresponding GraphQL query builders to declare
$since: Time, $until: Time variables and pass them through.
Fix integration test call sites for updated signatures.
Add appendTimeRangeConditions unit tests covering nil, since-only,
until-only, both, and table-qualified column cases. Add resolver
tests for Transactions, Operations, and StateChanges with time range
params: since in past/future, until before since validation error,
and combined with pagination/filters. Update existing resolver tests
for new since/until method signatures. Fix BatchGetByToID test calls
that had extra nil argument.
Resolve 5 conflicts by accepting timescale changes:
- Add bloom filter sparse indexes to transactions, operations, state_changes
- token_id column as BYTEA (from tokenid-bytea rebase)
- Add account_category composite index for state_changes
- Enable timescaledb.enable_sparse_index_bloom in docker-compose and test containers

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@aditya1702 aditya1702 changed the base branch from timescale to remove-filtering February 22, 2026 01:11
@aditya1702 aditya1702 closed this Feb 22, 2026
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.

1 participant