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

CCIP-2207 Boosting LogPoller performance by fixing how order by clauses are written #13026

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/proud-toys-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

Improving LogPoller read queries by properly sorting by multiple columns #updated
33 changes: 18 additions & 15 deletions core/chains/evm/logpoller/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ func (o *DSORM) SelectLatestLogByEventSigWithConfs(ctx context.Context, eventSig
AND event_sig = :event_sig
AND address = :address
AND block_number <= %s
ORDER BY (block_number, log_index) DESC LIMIT 1`, nestedBlockNumberQuery(confs))
ORDER BY block_number desc, log_index DESC
LIMIT 1
`, nestedBlockNumberQuery(confs))
var l Log

query, sqlArgs, err := o.ds.BindNamed(query, args)
Expand Down Expand Up @@ -425,7 +427,7 @@ func (o *DSORM) SelectLogsByBlockRange(ctx context.Context, start, end int64) ([
WHERE evm_chain_id = :evm_chain_id
AND block_number >= :start_block
AND block_number <= :end_block
ORDER BY (block_number, log_index)`
ORDER BY block_number, log_index`

var logs []Log
query, sqlArgs, err := o.ds.BindNamed(query, args)
Expand Down Expand Up @@ -456,7 +458,7 @@ func (o *DSORM) SelectLogs(ctx context.Context, start, end int64, address common
AND event_sig = :event_sig
AND block_number >= :start_block
AND block_number <= :end_block
ORDER BY (block_number, log_index)`
ORDER BY block_number, log_index`

var logs []Log
query, sqlArgs, err := o.ds.BindNamed(query, args)
Expand Down Expand Up @@ -488,7 +490,7 @@ func (o *DSORM) SelectLogsCreatedAfter(ctx context.Context, address common.Addre
AND event_sig = :event_sig
AND block_timestamp > :block_timestamp_after
AND block_number <= %s
ORDER BY (block_number, log_index)`, nestedBlockNumberQuery(confs))
ORDER BY block_number, log_index`, nestedBlockNumberQuery(confs))

var logs []Log
query, sqlArgs, err := o.ds.BindNamed(query, args)
Expand Down Expand Up @@ -520,7 +522,7 @@ func (o *DSORM) SelectLogsWithSigs(ctx context.Context, start, end int64, addres
AND address = :address
AND event_sig = ANY(:event_sig_array)
AND block_number BETWEEN :start_block AND :end_block
ORDER BY (block_number, log_index)`
ORDER BY block_number, log_index`

query, sqlArgs, err := o.ds.BindNamed(query, args)
if err != nil {
Expand Down Expand Up @@ -647,7 +649,7 @@ func (o *DSORM) SelectLogsDataWordRange(ctx context.Context, address common.Addr
AND substring(data from 32*:word_index+1 for 32) >= :word_value_min
AND substring(data from 32*:word_index+1 for 32) <= :word_value_max
AND block_number <= %s
ORDER BY (block_number, log_index)`, nestedBlockNumberQuery(confs))
ORDER BY block_number, log_index`, nestedBlockNumberQuery(confs))

var logs []Log
query, sqlArgs, err := o.ds.BindNamed(query, args)
Expand Down Expand Up @@ -678,7 +680,7 @@ func (o *DSORM) SelectLogsDataWordGreaterThan(ctx context.Context, address commo
AND event_sig = :event_sig
AND substring(data from 32*:word_index+1 for 32) >= :word_value_min
AND block_number <= %s
ORDER BY (block_number, log_index)`, nestedBlockNumberQuery(confs))
ORDER BY block_number, log_index`, nestedBlockNumberQuery(confs))

var logs []Log
query, sqlArgs, err := o.ds.BindNamed(query, args)
Expand Down Expand Up @@ -710,7 +712,7 @@ func (o *DSORM) SelectLogsDataWordBetween(ctx context.Context, address common.Ad
AND substring(data from 32*:word_index_min+1 for 32) <= :word_value
AND substring(data from 32*:word_index_max+1 for 32) >= :word_value
AND block_number <= %s
ORDER BY (block_number, log_index)`, nestedBlockNumberQuery(confs))
ORDER BY block_number, log_index`, nestedBlockNumberQuery(confs))

var logs []Log
query, sqlArgs, err := o.ds.BindNamed(query, args)
Expand Down Expand Up @@ -741,7 +743,7 @@ func (o *DSORM) SelectIndexedLogsTopicGreaterThan(ctx context.Context, address c
AND event_sig = :event_sig
AND topics[:topic_index] >= :topic_value_min
AND block_number <= %s
ORDER BY (block_number, log_index)`, nestedBlockNumberQuery(confs))
ORDER BY block_number, log_index`, nestedBlockNumberQuery(confs))

var logs []Log
query, sqlArgs, err := o.ds.BindNamed(query, args)
Expand Down Expand Up @@ -774,7 +776,7 @@ func (o *DSORM) SelectIndexedLogsTopicRange(ctx context.Context, address common.
AND topics[:topic_index] >= :topic_value_min
AND topics[:topic_index] <= :topic_value_max
AND block_number <= %s
ORDER BY (evm.logs.block_number, evm.logs.log_index)`, nestedBlockNumberQuery(confs))
ORDER BY block_number, log_index`, nestedBlockNumberQuery(confs))

var logs []Log
query, sqlArgs, err := o.ds.BindNamed(query, args)
Expand Down Expand Up @@ -805,7 +807,7 @@ func (o *DSORM) SelectIndexedLogs(ctx context.Context, address common.Address, e
AND event_sig = :event_sig
AND topics[:topic_index] = ANY(:topic_values)
AND block_number <= %s
ORDER BY (block_number, log_index)`, nestedBlockNumberQuery(confs))
ORDER BY block_number, log_index`, nestedBlockNumberQuery(confs))

var logs []Log
query, sqlArgs, err := o.ds.BindNamed(query, args)
Expand Down Expand Up @@ -838,7 +840,7 @@ func (o *DSORM) SelectIndexedLogsByBlockRange(ctx context.Context, start, end in
AND topics[:topic_index] = ANY(:topic_values)
AND block_number >= :start_block
AND block_number <= :end_block
ORDER BY (block_number, log_index)`
ORDER BY block_number, log_index`

var logs []Log
query, sqlArgs, err := o.ds.BindNamed(query, args)
Expand Down Expand Up @@ -872,7 +874,8 @@ func (o *DSORM) SelectIndexedLogsCreatedAfter(ctx context.Context, address commo
AND topics[:topic_index] = ANY(:topic_values)
AND block_timestamp > :block_timestamp_after
AND block_number <= %s
ORDER BY (block_number, log_index)`, nestedBlockNumberQuery(confs))
ORDER BY block_number, log_index
`, nestedBlockNumberQuery(confs))

var logs []Log
query, sqlArgs, err := o.ds.BindNamed(query, args)
Expand Down Expand Up @@ -901,7 +904,7 @@ func (o *DSORM) SelectIndexedLogsByTxHash(ctx context.Context, address common.Ad
AND address = :address
AND event_sig = :event_sig
AND tx_hash = :tx_hash
ORDER BY (block_number, log_index)`
ORDER BY block_number, log_index`

var logs []Log
query, sqlArgs, err := o.ds.BindNamed(query, args)
Expand Down Expand Up @@ -949,7 +952,7 @@ func (o *DSORM) SelectIndexedLogsWithSigsExcluding(ctx context.Context, sigA, si
AND b.event_sig = :sigB
AND b.block_number BETWEEN :start_block AND :end_block
AND b.block_number <= %s
ORDER BY block_number,log_index ASC`, nestedQuery, nestedQuery)
ORDER BY block_number, log_index`, nestedQuery, nestedQuery)

var logs []Log
query, sqlArgs, err := o.ds.BindNamed(query, args)
Expand Down
Loading