aspose file tools*
The moose likes JDBC and the fly likes MySQL indexing - is it a tree? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "MySQL indexing - is it a tree?" Watch "MySQL indexing - is it a tree?" New topic
Author

MySQL indexing - is it a tree?

Ivan Jouikov
Ranch Hand

Joined: Jul 22, 2003
Posts: 269
I have a table,



which will store account stuff, such as address email, name, phone, and whatever the hell I come up with.

So you get the idea, the table will be huge. For every account there will be like 10 different rows.

So, I was wandering, is it the best way to do INDEX(accID), INDEX(name), will that give you a tree structure? Because efficiency here will be the key. I forsee my statements to retrieve an attribute to be something like

SELECT value FROM account_attributes WHERE accID='?' AND name='?'

... Is this how you would do it? Or is there a more efficient way?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156

Ivan,
Creating just the index on accID is enough. The database will get the 10 or so rows and then look through only those for the given name. This happens very quickly.

While, you could do an index of accID and name, it would be roughly 2/3 as large as the full table. So it wouldn't be as fast.

Having 2 separate indexes for accID and name doesn't help you because the database can only use one at a time.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ivan Jouikov
Ranch Hand

Joined: Jul 22, 2003
Posts: 269
Thx!
 
jQuery in Action, 2nd edition
 
subject: MySQL indexing - is it a tree?