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

Make extra table constraints subqueried #562

Merged

Conversation

msdemlei
Copy link
Contributor

@msdemlei msdemlei commented Jun 26, 2024

There has been a fairly evil thinko in the way we've been writing constraints requiring extra tables. What we did is something like

NATURAL JOIN rr.table_column
WHERE ucd like 'phot.mag;%'

This is innocent enough in hand-written, one-shot queries. For us with our complicated way of pulling all capabilities in one go, it's bad, because if there's n columns with a matching UCD, then every interface will appear n times in our interfaces list. That was relatively harmless before we became more uptight about duplicated interfaces in #505 and environment. It is a disaster now, and so we want to change our style to

WHERE ivoid in (select ivoid from rr.table_column WHERE ucd like 'phot.mag;%').

This is probably not going to be much of a difference in terms of what the databases actually execute; the query planner should take care of that.

Oh, by the way, this PR should be merged after #561 and contains that commit already.

@msdemlei msdemlei force-pushed the make-extra-table-constraints-subqueried branch from d7a186e to ca6584a Compare June 27, 2024 04:50
@bsipocz bsipocz added this to the v1.6 milestone Jun 27, 2024
This is a lot more stable versus extra rows than the natural joins we've
been doing so far.
@msdemlei msdemlei force-pushed the make-extra-table-constraints-subqueried branch from ca6584a to 3bc52a3 Compare June 27, 2024 06:35
@ManonMarchand
Copy link
Member

LGTM except a question: did you intentionally do three sub-queries for the Freetext constraint? Is this more efficient than a OR in a single sub-query?

@msdemlei msdemlei force-pushed the make-extra-table-constraints-subqueried branch from 3bc52a3 to 8a726d6 Compare June 27, 2024 09:14
@msdemlei
Copy link
Contributor Author

Ok, sorry about the whitespace and the pdb.

This should now clear the CI except for the mysterious linkcheck message. If a sphinx deity can help me out there, that'd be much appreciated. But perhaps this can go even with this broken link?

@msdemlei
Copy link
Contributor Author

msdemlei commented Jun 27, 2024 via email

@@ -284,14 +318,15 @@ def _get_or_condition(self, service):
return super().get_search_condition(service)


class Author(Constraint):
class Author(SubqueriedConstraint):
Copy link
Member

Choose a reason for hiding this comment

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

sphinx is failing as in the API docs it tries to link to the baseclass, but the new class hasn't been added to the public API and therefore there is no API docs available for it.

I'll add a commit that resolves this issue, take it or leave it (I mean we can work around not exposing the class in the public API if necessary).

FWIW, Constraint is in the public API, so I don't think it's a big problem to add the new one, too.

@msdemlei
Copy link
Contributor Author

msdemlei commented Jun 28, 2024 via email

@ManonMarchand
Copy link
Member

If @bsipocz also approves I think this can be merged

@bsipocz
Copy link
Member

bsipocz commented Jun 28, 2024

I haven't reviewed the content, but 100% trust your review, so go for the merge.

The only thing to check for is if the PR is fixing a bug that is already in the release, then it can have the bugfix milestone (atm I'm not sure if we have one more of those or 1.6 next, so we don't care about changelog consistency)

@ManonMarchand ManonMarchand merged commit 29383f0 into astropy:main Jun 28, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants