Jamroom Logo Jamroom 5 Core
is now Open Source!
User Support Forum Archive (Read Only)
Jamroom Developers:
create table INDEX question
littlericky



Joined: 08 Feb 2007
Posts: 601

Posted: 08/30/09 12:54 
In the below code what does the
# INDEX youtube_band_id (youtube_band_id),
# INDEX youtube_video_time (youtube_video_time),
# INDEX youtube_video_category (youtube_video_category(15))
actually do? Why is it used for only 3 of the 5 fields?




Code
# // Create our You Tube videos table 
# $tbl = "CREATE TABLE {$jamroom_db['jrYouTubeVideos']} ( 
#   youtube_id INT(7) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 
#   youtube_band_id INT(7) UNSIGNED NOT NULL, 
#   youtube_video_id VARCHAR(25) NOT NULL DEFAULT '', 
#   youtube_video_time INT(11) UNSIGNED NOT NULL DEFAULT '0', 
#   youtube_video_category VARCHAR(30) NOT NULL DEFAULT '', 
#   INDEX youtube_band_id (youtube_band_id), 
#   INDEX youtube_video_time (youtube_video_time), 
#   INDEX youtube_video_category (youtube_video_category(15)) 
# )"; 
# dbVerifyTable($jamroom_db['jrYouTubeVideos'],$tbl); 


Back to top
SteveX
Ultrabubble


Joined: 30 Aug 2005
Posts: 8792
Location: Ultrabubble

Posted: 08/31/09 05:13 
mysql will build indexes of these columns which makes queries using these faster.

Here is a better explanation:
http://www.tizag.com/mysqlTutorial/mysql-index.php


_________________
Kulshi Mezian!

"Stranger from another planet, welcome to our hole. Just strap on your guitar and we'll play some rock and roll"

Ultrabubble create things.
Back to top
littlericky



Joined: 08 Feb 2007
Posts: 601

Posted: 08/31/09 14:09 
Thanks Steve. I'm attempting to create a simple widget but my lack of php skills is maing it LESS than simple Smile

Back to top
Brian
Jamroom Team


Joined: 09 Jul 2003
Posts: 37583
Location: Seattle, WA

Posted: 09/01/09 11:28 
The "general" rule of thumb is that:

- if the column is used in a WHERE condition
- if the column is used in a JOIN condition

you should index it. However, there is an INSERT/UPDATE/DELETE penalty when you have column indexes, since when data is inserted, updated or deleted in the database, the respective INDEX's must also be updated to stay in sync with the new data, so this is why you don't just simply index every column.

Hope this helps!

- Brian


_________________
Make sure and check out:
* The Jamroom FAQ
* The Jamroom Documentation
Back to top
Display posts from previous:   
User Support Forum Archive (Read Only)
Jamroom Developers

 
Solutions
• Social Media Platform
• Social Networking Software
• Musician Website Manager
• Community Builder
Products
• Jamroom Core
• Jamroom Addons
• Jamroom Modules
• Jamroom Marketplace
Support
• Support Forum
• Documentation
• Support Center
• Contact Support
Community
• Community Forum
• Member Sites
• Developers
Company
• About Us
• Contact Us
• Privacy Policy
©2003 - 2010 Talldude Networks, LLC.