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

Modify outer left join query to use existing index. #822

Merged
merged 1 commit into from
Jan 14, 2022

Conversation

winder
Copy link
Contributor

@winder winder commented Jan 12, 2022

Summary

Modify outer left join query to use existing index.

Test Plan

Manual performance testing and EXPLAIN analysis.

@tolikzinovyev
Copy link
Contributor

what happens when t.extra->>'root-intra' is empty string?

@winder
Copy link
Contributor Author

winder commented Jan 14, 2022

what happens when t.extra->>'root-intra' is empty string?

That case is why the query needs to be left outer join instead of a simple join. When nothing has matched for the root transaction, the rest of the result is still returned.

Here is a test query to demonstrate:

select
	root.txid root_txid,
	t.extra,
	t.intra,
	t.round
from
	txn t
join block_header h on
	t.round = h.round
left outer join txn root on
	t.round = root.round
	and (t.extra->>'root-intra')::int = root.intra
where
	t.round = 18461108
root_txid                                           |extra                                                                                   |intra|round   |
----------------------------------------------------+----------------------------------------------------------------------------------------+-----+--------+
                                                    |{}                                                                                      |    0|18461108|
                                                    |{}                                                                                      |    1|18461108|
                                                    |{}                                                                                      |    2|18461108|
                                                    |{}                                                                                      |    3|18461108|
                                                    |{}                                                                                      |    4|18461108|
                                                    |{}                                                                                      |    5|18461108|
                                                    |{}                                                                                      |    6|18461108|
                                                    |{}                                                                                      |    7|18461108|
5DVVQAULIA4RBYPBUNAPTCBNQXUFXBR6SGZ4NHV7XTF77LMTUTNQ|{"root-txid": "5DVVQAULIA4RBYPBUNAPTCBNQXUFXBR6SGZ4NHV7XTF77LMTUTNQ", "root-intra": "7"}|    8|18461108|
5DVVQAULIA4RBYPBUNAPTCBNQXUFXBR6SGZ4NHV7XTF77LMTUTNQ|{"root-txid": "5DVVQAULIA4RBYPBUNAPTCBNQXUFXBR6SGZ4NHV7XTF77LMTUTNQ", "root-intra": "7"}|    9|18461108|
                                                    |{}                                                                                      |   10|18461108|
                                                    |{}                                                                                      |   11|18461108|
                                                    |{}                                                                                      |   12|18461108|

Copy link
Contributor

@tolikzinovyev tolikzinovyev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming there is a unit test, LGTM!

@winder winder marked this pull request as ready for review January 14, 2022 19:35
@winder winder merged commit 1313f26 into develop Jan 14, 2022
@winder winder deleted the will/fix-inner-txn-query branch January 14, 2022 19:35
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.

2 participants