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

upgrade: improve delete dropped udf upgrade job efficiency #104512

Conversation

chengxiong-ruan
Copy link
Contributor

Informs: https://github.com/cockroachlabs/support/issues/2364

Release note (performance improvement): this commit makes the delete descriptors of dropped functions upgrade job more efficient. It used to look at every single id until the max descriptor id which was very inefficient when the max descriptor id really large, in which case the upgrade job took very long even there was no function descriptor at all. This commit changed it to actually query upper bound id of each batch.

@chengxiong-ruan chengxiong-ruan requested a review from a team as a code owner June 7, 2023 15:00
@blathers-crl
Copy link

blathers-crl bot commented Jun 7, 2023

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@chengxiong-ruan chengxiong-ruan force-pushed the 20230607-more-efficient-udf-upgrade branch 2 times, most recently from 7a8e809 to f9adf43 Compare June 7, 2023 15:17
Copy link
Collaborator

@andyyang890 andyyang890 left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @chengxiong-ruan)


pkg/upgrade/upgrades/delete_descriptors_of_dropped_functions.go line 45 at r1 (raw file):

    FROM 
      system.descriptor
    WHERE id > $1

Just wondering, would it be a lot more inefficient to instead have the to_json CTE not have a WHERE clause and have to_delete maybe have something like LIMIT 50 on it? (Or maybe have the LIMIT 50 on the main SELECT itself.) And then we'd loop the query until no more rows are affected?

I still worry that looping over the descriptor IDs might be too slow and if these kind of descriptors are rare to begin with, somewhat inefficient still?

@chengxiong-ruan
Copy link
Contributor Author

pkg/upgrade/upgrades/delete_descriptors_of_dropped_functions.go line 45 at r1 (raw file):

Just wondering, would it be a lot more inefficient to instead have the to_json CTE not have a WHERE clause and have to_delete maybe have something like LIMIT 50 on it? (Or maybe have the LIMIT 50 on the main SELECT itself.) And then we'd loop the query until no more rows are affected?

I think the optimizer would push the where clause down to to_json if we put it in the main SELECT (which do the delete).

And then we'd loop the query until no more rows are affected?

I think with this approach, we still need to track the progress somehow. Otherwise it would start from the very first descriptor if there're actually some function descriptors. Maybe we could have the delete query to return the IDs as well then still filter by IDs. But I think by explicitly looping through IDs, each small batch is light and won't scan too much data.

I still worry that looping over the descriptor IDs might be too slow and if these kind of descriptors are rare to begin with, somewhat inefficient still?

yeah, the thing is that we have to look at every single descriptor to tell if it's a function descriptor and then to tell if it's dropped. But I won't worry about the IDs looping as long as it only look at actual existing IDs. From what I saw by testing this new. upgrade with the 4 thousand descriptor debug zip, it's much much faster now.

@chengxiong-ruan chengxiong-ruan force-pushed the 20230607-more-efficient-udf-upgrade branch from f9adf43 to c757411 Compare June 7, 2023 16:56
@chengxiong-ruan chengxiong-ruan added the backport-23.1.x Flags PRs that need to be backported to 23.1 label Jun 7, 2023
Copy link
Collaborator

@andyyang890 andyyang890 left a comment

Choose a reason for hiding this comment

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

:lgtm: just one small nit

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @chengxiong-ruan)


pkg/upgrade/upgrades/delete_descriptors_of_dropped_functions.go line 45 at r1 (raw file):

I think with this approach, we still need to track the progress somehow. Otherwise it would start from the very first descriptor if there're actually some function descriptors.

Ah I see, I guess because it's not as straightforward as DELETE FROM ..., you can't just use a LIMIT directly.


pkg/upgrade/upgrades/delete_descriptors_of_dropped_functions.go line 94 at r2 (raw file):

				batchSize,
			)
			batchMaxID := int64(tree.MustBeDInt(row[0]))

nit: this line should probably go after the err != nil check

Release note (performance improvement): this commit makes the
`delete descriptors of dropped functions` upgrade job more efficient.
It used to look at every single id until the max descriptor id which
was very inefficient when the max descriptor id really large, in which
case the upgrade job took very long even there was no function
descriptor at all. This commit changed it to actually query upper bound
id of each batch.
@chengxiong-ruan chengxiong-ruan force-pushed the 20230607-more-efficient-udf-upgrade branch from c757411 to b20d5ac Compare June 7, 2023 21:32
@chengxiong-ruan
Copy link
Contributor Author

pkg/upgrade/upgrades/delete_descriptors_of_dropped_functions.go line 94 at r2 (raw file):

Previously, andyyang890 (Andy Yang) wrote…

nit: this line should probably go after the err != nil check

done. good catch!

@chengxiong-ruan
Copy link
Contributor Author

tftr!
bors r+

@craig
Copy link
Contributor

craig bot commented Jun 8, 2023

Build failed:

@chengxiong-ruan
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Jun 8, 2023

Build succeeded:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-23.1.x Flags PRs that need to be backported to 23.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants