Skip to content

Database user backend improvements - #3939

Closed
icewind1991 wants to merge 9 commits into
masterfrom
user-database
Closed

icewind1991 wants to merge 9 commits into
masterfrom
user-database

Conversation

@icewind1991

Copy link
Copy Markdown
Contributor

Adds a field uid_lower to the database (filled during upgrade) as a way to prevent having to use LOWER() in the sql and make proper use of indexes.

Also some generic cleanup for the backend.

cc @karlitschek @DeepDiver1975 @dragotin @tanghus

@karlitschek

Copy link
Copy Markdown
Contributor

👍

Comment thread lib/user/database.php Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This assumes SQL LOWER() is equivalent to strtolower(). Is this guranteed?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe it will be fine since we don't allow any special characters e.g. umlauts in usernames where strtolower and LOWER might act differently.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Okay.

@bantu

bantu commented Jul 4, 2013

Copy link
Copy Markdown

@tanghus

tanghus commented Jul 4, 2013

Copy link
Copy Markdown
Contributor

@icewind1991 What is the problem with using LOWER() in the first place? Issue #?

@tanghus

tanghus commented Jul 4, 2013

Copy link
Copy Markdown
Contributor

If it is that LOWER isn't guaranteed work the same the same way as PHP strtolower, couldn't we instead do e.g.

'UPDATE `*PREFIX*users` SET `displayname` = ? WHERE LOWER(`uid`) = LOWER(?)'

and don't use strtolower?

@icewind1991

Copy link
Copy Markdown
Contributor Author

The problem with lower is that it breaks indexes, since we're not querying the index but a function result.

Comment thread lib/user/database.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we switch to executeAudited while we're in here?

@MTGap

MTGap commented Jul 4, 2013

Copy link
Copy Markdown
Contributor

I'm thinking that instead of a uid_lower column, we just store the lower case uid in the uid column and the proper case in the displayname column. If a display name is set we just overwrite the proper case, because it isn't necessary to keep around anymore.

@icewind1991

Copy link
Copy Markdown
Contributor Author

I'm thinking that instead of a uid_lower column, we just store the lower case uid in the uid column and the proper case in the displayname column. If a display name is set we just overwrite the proper case, because it isn't necessary to keep around anymore.

Because the non-lowercase uid is already used all over the place, so we need to keep that the same.

@ghost

ghost commented Jul 24, 2013

Copy link
Copy Markdown

@icewind1991

Copy link
Copy Markdown
Contributor Author

@DeepDiver1975 @MTGap @tanghus can this be merged?

@DeepDiver1975

Copy link
Copy Markdown
Contributor

@icewind1991 is there a migration of data in here? for existing entries uid_lower has to be filled somehow - THX

@icewind1991

Copy link
Copy Markdown
Contributor Author

Yes, you can test it by trying to login after the upgrade or look at the db

@DeepDiver1975

Copy link
Copy Markdown
Contributor

@icewind1991 please point me to the code which is doing the migration - THX

@dragotin

Copy link
Copy Markdown
Contributor

Ok, I tested that and checked my slow query log that gives me information about which tables are accessed without using suitable indexes.

  • Generally, the query of the user table is fine now and seems to use an index.
  • This happens without an index still:
SELECT `gid` FROM `oc_group_user` WHERE `uid` = 'kf';

Are we sure that in all the tables which use the uid string we use the correct way (weather its lowercase or not , dunno) ?

And, the population of the new lowercase column did not happen automatically for me, I had to update by hand. The column was created on upgrade.
From my side because of that: 👎

@DeepDiver1975

Copy link
Copy Markdown
Contributor

And, the population of the new lowercase column did not happen automatically for me,

@icewind1991 this is what I've been asking for ... 👿

@icewind1991

Copy link
Copy Markdown
Contributor Author

Strange, the upgrade mechanism worked for me when I last tested it, will look into it.

@VicDeo

VicDeo commented Jul 25, 2013

Copy link
Copy Markdown
Contributor

Relations:
#1657
#1314
#3293

@MorrisJobke

Copy link
Copy Markdown
Contributor

@icewind1991 What's the current status on this?

@karlitschek

Copy link
Copy Markdown
Contributor

What is the status of that? I still think this is a good idea in general.

@icewind1991

Copy link
Copy Markdown
Contributor Author

Will close this one for now, similar improvements are better made in a new pr if needed

@jancborchardt
jancborchardt deleted the user-database branch February 19, 2014 10:30
@lock lock Bot locked as resolved and limited conversation to collaborators Aug 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants