neoform Posted May 9, 2008 Share Posted May 9, 2008 Is there any speed penalty if I have a table with no primary key (but other indexes that get used instead) ? Quote Link to comment https://forums.phpfreaks.com/topic/104809-table-without-primary-key/ Share on other sites More sharing options...
fenway Posted May 9, 2008 Share Posted May 9, 2008 Hard to imagine how you're working with a table without a PK... unless you truly have another unique identifier across multiple columns... Quote Link to comment https://forums.phpfreaks.com/topic/104809-table-without-primary-key/#findComment-536694 Share on other sites More sharing options...
neoform Posted May 9, 2008 Author Share Posted May 9, 2008 Well, for example a table that contains logs. I never need to uniquely identify any one particular row, however I want to access the data based on fields such as date, so I have the date field indexed, but no primary key since that key would never be used, and therefore cause wasted cycles and ram. Quote Link to comment https://forums.phpfreaks.com/topic/104809-table-without-primary-key/#findComment-536723 Share on other sites More sharing options...
fenway Posted May 9, 2008 Share Posted May 9, 2008 I suppose so.. as long as your query will use some sort of index, you'll be fine... incidentally, you might want to look at the ARCHIVE table type as an alternative. Quote Link to comment https://forums.phpfreaks.com/topic/104809-table-without-primary-key/#findComment-536919 Share on other sites More sharing options...
neoform Posted May 9, 2008 Author Share Posted May 9, 2008 hmmmm, ARCHIVE looked cool till I read the part that says "No indexing is allowed".. I can't imagine this would work well in on an analytics table where i need to count hits based on date. Quote Link to comment https://forums.phpfreaks.com/topic/104809-table-without-primary-key/#findComment-536947 Share on other sites More sharing options...
fenway Posted May 9, 2008 Share Posted May 9, 2008 hmmmm, ARCHIVE looked cool till I read the part that says "No indexing is allowed".. I can't imagine this would work well in on an analytics table where i need to count hits based on date. Really depends how much of your data your analyze at one time... if it's about 30% of the table, mysql won't use an index regardless, archive or not Quote Link to comment https://forums.phpfreaks.com/topic/104809-table-without-primary-key/#findComment-536987 Share on other sites More sharing options...
neoform Posted May 9, 2008 Author Share Posted May 9, 2008 I usually pull up a days worth of logs from a table that contains years worth of info.. Quote Link to comment https://forums.phpfreaks.com/topic/104809-table-without-primary-key/#findComment-537004 Share on other sites More sharing options...
crtreedude Posted May 10, 2008 Share Posted May 10, 2008 Hard to imagine how you're working with a table without a PK... unless you truly have another unique identifier across multiple columns... If it is merely logs, and you don't have to work with individual rows, it actually makes sense to have no primary key. Uniqueness must be checked during insert with a primary key, but with a simple index, no. If one needs to update or delete individual records, you need a primary key, or uniqueness, otherwise, not really. For example, you can delete all records for a range of dates. Quote Link to comment https://forums.phpfreaks.com/topic/104809-table-without-primary-key/#findComment-537875 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.