Author Topic: Referencing a username  (Read 1084 times)

ST-Mike

  • Guest
Referencing a username
« on: November 27, 2009, 03:26:25 PM »
Admins have ignored my deletion request - if you're not going to delete my account then don't have the option there please.
« Last Edit: March 15, 2011, 07:57:25 PM by None »

Offline Nox

  • Level 35
  • **
  • Posts: 738
  • Reputation: +12/-2
    • View Profile
Re: Referencing a username
« Reply #1 on: November 27, 2009, 03:30:24 PM »
I think numerical id would be faster - shorter, more easily sortable etc., not to mentioned never changed, easily used manually, occupies much less space in the end 'cause of references...
Meet us at an IRC irc.freenode.net #bbg as well
Enjoy http://spiritbeacon.noxart.cz/ !

Online Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,133
  • Reputation: +26/-1
    • View Profile
Re: Referencing a username
« Reply #2 on: November 27, 2009, 05:03:59 PM »
Never use varchar in MyISAM (except for messages). It makes the whole table much slower. You would be better to even split the table in two if it would remove the need for varchar in the most used part of the table.

As for username vs id+JOIN, it depends how often the table is accessed (for buddy list I would probably go for id+JOIN). Generally, avoiding JOIN is faster (exceptions), the drawback is bloated database and more complex code (breakage of normalisation has some drawbacks, althrough it is not as huge cost as most people think).

As for selecting, then obviously id is far faster than any string. So storing username to use it as an identifier when you could use id is just insane :)

ST-Mike

  • Guest
Re: Referencing a username
« Reply #3 on: November 27, 2009, 05:08:48 PM »
Admins have ignored my deletion request - if you're not going to delete my account then don't have the option there please.
« Last Edit: March 15, 2011, 07:57:19 PM by None »

Offline 133794m3r

  • Level 22
  • *
  • Posts: 265
  • Reputation: +2/-0
    • View Profile
Re: Referencing a username
« Reply #4 on: November 28, 2009, 10:36:20 PM »
wait now i saw that you shouldn't use it for MyISAM abut what about INNODB should you use something like char(20)? instead of varchar(20) b/c i read in that tips thread that the peformance is lightly greater. So how much of a difference is the performance between teh two?

Offline Marek

  • Level 17
  • *
  • Posts: 170
  • Reputation: +6/-0
  • XHTML, CSS, JS, PHP and MySQL are my pantheon.
    • View Profile
Re: Referencing a username
« Reply #5 on: November 29, 2009, 12:55:40 AM »
A numerical id will still be faster than a char, if I'm not mistaken.

For the original question, I think the best balance of simplicity vs performance is using an int id and a join for the username. This is the "conventional" way to structure a relation of this sort. Don't optimize prematurely: start with the conventional approach, and then if you see that in practice, the query's performance is a bottleneck, then consider optimizing it.

The reason why optimizing prematurely can be bad is that often, the real bottlenecks are in different spots than you first think. So it's best to have concrete evidence in the form of performance profiling, and only then optimizing, starting with what can be improved the most.

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: Referencing a username
« Reply #6 on: November 29, 2009, 08:29:01 AM »
nano's suggestions above are my advice as well. Well done, nano! :)

There is no need to copy the username to various tables and, indeed, numbers are always faster than characters. Remember, everything with computers eventually ends up as 1s and 0s. The fewer 1s and 0s you end up with, the better! lol :P
Idiocy - Never underestimate the power of stupid people in large groups.


 


SimplePortal 2.3.3 © 2008-2010, SimplePortal