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

Remove nextrun index #107

Merged
merged 4 commits into from
Dec 3, 2020
Merged

Remove nextrun index #107

merged 4 commits into from
Dec 3, 2020

Conversation

tfrommen
Copy link
Contributor

@tfrommen tfrommen commented Dec 1, 2020

This PR removes the nextrun index on the jobs table, as per discussion in #106.

*
* Remove nextrun index as it negatively affects performance.
*/
function upgrade_database_4() {
Copy link
Member

Choose a reason for hiding this comment

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

Can we also update the v3 alter command so that someone migrating from v2 -> v4 doesn't get a useless index in the meantime?

Copy link
Contributor

Choose a reason for hiding this comment

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

@rmccue like that?

@roborourke
Copy link
Contributor

I think although it's a database change there's no functional change and it solves a problem so I suggest we do this as a patch release.

Copy link
Contributor

@roborourke roborourke left a comment

Choose a reason for hiding this comment

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

I approve this message.

@roborourke roborourke merged commit e8b1e9a into master Dec 3, 2020
@roborourke roborourke deleted the remove-nextrun-index branch December 3, 2020 10:26
global $wpdb;

$query = "ALTER TABLE `{$wpdb->base_prefix}cavalcade_jobs`
DROP INDEX `nextrun`";
Copy link
Member

Choose a reason for hiding this comment

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

Does this need an IF EXISTS or something too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rmccue well, it doesn't need it, but this will mean that the ALTER TABLE statement will be executed no matter what. It's not a big deal, but also one of the reasons why I didn't change the v3 statement. I also thought that keeping old versions (even if this means unnecessarily introducing an intermediary index) as expected would be a good thing.

MySQL does not support IF EXISTS for DROP INDEX—MariaDB does, though.
So, we would need to run a query to check for the index, and if present, drop it. That's not really any better than running the above quick and meaningless ALTER TABLE query, but the difference would be to only run a write query if necessary.

Copy link
Contributor Author

@tfrommen tfrommen Dec 8, 2020

Choose a reason for hiding this comment

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

Following up on this, just to clarify the "not a big deal": MySQL will throw an error for trying to drop an index that does not exist. But WordPress/PHP will not complain (and work just fine) as this is, fortunately, the only thing that this query should do. wp cavalcade upgrade will execute successfully.

Personally, I think it best to change the v3 statement back to what it was initially. If there were tests for the individual upgrade routines, or tests making use of them to prepare the test data/context, they would have needed to be changed. Would we have done/wanted that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe, we don't have tests for the upgrade routines themselves as that's quite difficult to do. Easier to let the initial set up happen and test the core functionality.

If upgrades happen without a hitch still then I think changing anything now isn't really much of a priority. We could add tests for the upgrade routines in future but it feels like high effort for low return. The database creation and upgrade process is not tested individually but as a whole in the sense it needs to work for the rest of the tests to pass which is good enough right now.

Copy link
Contributor Author

@tfrommen tfrommen Dec 8, 2020

Choose a reason for hiding this comment

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

@roborourke that's not what I meant. I wasn't asking for tests. You were able to "easily" adapt the v3 statement because there were no tests that broke. I was just questioning if we would have changed anything in a previous version if there would have been tests (or other kind of dependent code) that broke. 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it depends on what is being changed so there's no generic answer for me. I guess you're saying that it's bad practice (which is totally fair!) and we should change the v3 database step back, but at least in this instance it doesn't actually break anything.

Speaking more generally if there were tests or other dependent code that broke as a result of some change it also depends, maybe the tests would need fixing or updating, or we wouldn't make that change, or we would approach it completely differently. We approach it on a case by case basis.

We can certainly keep the mindset in future for cases where there might not be existing tests but question "what if there were" and consider what might break or how it might affect the approach we take. That sounds like a good idea to me. On the other hand in cases where there aren't really external dependencies or integrations in play I don't personally see tests themselves (or other internal APIs for example) as immutable.

Copy link
Member

Choose a reason for hiding this comment

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

I'd rather we silently swallow the error here, because otherwise updating v2 -> v4 will cause MySQL to create an index that it immediately drops. Creating indexes is expensive (it's an O(N) operation, and a slow one), so the cost of doing this is significant, even if it's less architecturally pure to do so.

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.

None yet

3 participants