![]() |
MySQL retrieve method question. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: MySQL retrieve method question. (/showthread.php?tid=49602) |
MySQL retrieve method question. - El Forum - 02-26-2012 [eluser]Unknown[/eluser] Hello everyone, I just have a quick question regarding Key usage in MySQL. In the documentation under the "News" tutorial it tells us to create the following: Code: CREATE TABLE news ( My question is, why is it necessary to create "KEY slug (slug)"? Why not just retrieve the slug by the slug content in the column name? For example "SELECT * FROM news WHERE slug = '$slug'" In other words, I am curious to know the need for making slug a "KEY" in the MySQL table. I am somewhat of a newbie, any response is appreciated. MySQL retrieve method question. - El Forum - 02-26-2012 [eluser]CroNiX[/eluser] Because it will be found a lot faster if that key is indexed, and since you will be loading the entry by the slug name, it makes sense to index it for faster retrieval. MySQL retrieve method question. - El Forum - 02-26-2012 [eluser]InsiteFX[/eluser] KEY creates an index, which speeds it up. MySQL retrieve method question. - El Forum - 02-26-2012 [eluser]Unknown[/eluser] [quote author="CroNiX" date="1330292865"]Because it will be found a lot faster if that key is indexed, and since you will be loading the entry by the slug name, it makes sense to index it for faster retrieval.[/quote] [quote author="InsiteFX" date="1330293060"]KEY creates an index, which speeds it up.[/quote] That explains a lot, thank you for the insight! |