Log in

View Full Version : mod_rewrite effects on querying database



superjadex12
07-25-2008, 06:22 PM
Hello, I have a wordpress blog that I'm just testing around.
I've chosen "friendly" urls which look like this:
http://www.self-made.us/2008/06/orga...n-of-material/
where the link is in this format : /[year]/[month]/[title of post]/

The "normal" link would look like this :
http://www.self-made.us/?p=4
where p equals the database primary key of which the table is indexed.

My question is how in the world do you query the database using the first link? Do they really find the row by searching on the text-based "title of post" field? If so, this seems like such a huge performance hit, over having direct access to the primary key in integer form, as shown in the second link. Also consider that some blogs have hundreds and hundreds of pages.

If you notice www.digg.com also does this, and they must store literally MILLIONS of pages. How can they access their data so quick, seemingly using a word-based search?

So how does the first link actually work?
Thanks!

motormichael12
07-25-2008, 11:07 PM
I have wondered this looking at wikipedia :O

tfit
08-01-2008, 10:38 AM
I played a bit with it, but never was sure about the performances hit. I only had small tables.
Ok, what i did was strip the string. Well you're doing the same but you combine.
2008 I would make a table, 06 a value of field month in the table, i would strip orga.. from the title string and put in field title. Finally, the complete title in another table where the date match would that of date of the first table. You than can match the substring with the complete string with the same date.
Again this was only experimental and not very well tested.
I hope someone can make some improvements so I can use it with a better implementation:D