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

Automatically delete duplicate keys in oc_appconfig table #8469

Closed
PVince81 opened this issue May 6, 2014 · 9 comments
Closed

Automatically delete duplicate keys in oc_appconfig table #8469

PVince81 opened this issue May 6, 2014 · 9 comments

Comments

@PVince81
Copy link
Contributor

PVince81 commented May 6, 2014

In some migration cases, the oc_appconfig table contains duplicate keys.
These need to be deleted/resolved on upgrade.

@icewind1991

@icewind1991
Copy link
Contributor

Looking at the code it seems that latest row (in whatever order the sql server feels like) will be used while reading the values.

Do you know a clean (preferably pure SQL) way to remove the tables that are ignored while reading?
Only method I can think of at the moment is deleting all rows with duplicated keys and re-adding the values.

@PVince81
Copy link
Contributor Author

PVince81 commented May 6, 2014

Not really, and the order will probably vary depending on the DB engine. I remember that SQLite doesn't auto sort anything. (summonning @bantu for extra support)

Maybe doing a DELETE with a "LIMIT" parameter ?

Also, possibly related: #8252 adding primary keys. Hopefully the end of duplicate stuff!

@bantu
Copy link

bantu commented May 6, 2014

Looking at the code it seems that latest row (in whatever order the sql server feels like) will be used while reading the values.

I would rather not rely on that actually being the case. I am pretty sure this won't hold for all DBMSes. If there is no consent it is basically a) Pick a random value or b) ask the user.

@karlitschek
Copy link
Contributor

Ask the user is not an option because there is no way the user can do the right decision.

@icewind1991
Copy link
Contributor

There is no need to ask the user. The code that reads the appconfig values from the database already implicitly chooses one of the values which is the same one as the over who we should keep during migration. That way the configuration stays the same and from the users perspective nothing had changed.

@bantu
Copy link

bantu commented May 6, 2014

The code that reads the appconfig values from the database already implicitly chooses one of the values which is the same one as the over who we should keep during migration.

There is no guarantee that this selection is deterministic. Different queries may return different results. Internal database reorganisation may change returned values for the same query. So this strategy is basically the same as "pick a random value" but possibly with a higher chance of returning the correct value. I am fine with doing it like that.

@bantu
Copy link

bantu commented May 6, 2014

Here is some pseudocode that might be helpful. I probably wouldn't invest more time to be more clever when deleting rows.

SELECT appid, configkey, COUNT(configvalue)
FROM oc_appconfig
GROUP BY appid, configkey
HAVING COUNT(configvalue) > 1

while ($row = fetchRow()) {
    // Use Appconfig to fetch value
    // Delete all rows
    // Insert single new row
}

@PVince81
Copy link
Contributor Author

PVince81 commented Jun 2, 2014

From what I saw while testing #7015, it seems that we already have an index on oc_appconfig in OC 6.
This means that this issue with duplicate keys can only happen when upgrading from OC 5.
I think we probably ask users to never upgrade directly from OC 5 to OC 7, so if we do want to implement a fix for this, it would have to go in OC 6.

Both OC 6 and OC 7 have an index in oc_appconfig, but not OC 5.

@karlitschek
Copy link
Contributor

O.K. Closing for now.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants