0

i have two questions, that i encountered in my learning project

1) Setting: i have a table with 17 fields.

i just need 15 of the 17 fields in my programm is ist better to get all fields with * or should i declare the 15 fields?

2) Setting: i want to create Metatags for my site, the Metatag values are in an array, with some other data(8 fields for the metatags 7 for page settings -> result of the SQL query above)

at the moment i filter it with an if statement like if($key != "name1" || $key != "name2" ...|| $line != '')

is it better so seperate the metatag data and save it in a new array? or should i seperate it in the database and put it in an seperate table?

Thanks n.redick

  • The performance difference from fetching 15 instead of 17 rows should be little to none. The only time this might matter is with a framework whose query creates an array with all fetched columns of thousands of rows, thus making the array too big to save. – Robin Castlin Mar 23 '12 at 07:42
  • in this case its always one fetched row, but i dont need all fields of the row (2 are useless later on), so the array to big problem should not occur. But an newbie question on the site: the query string would be alot longer with the 15 fields all mentioned after the SELECT. This additional Data, which must be send to the MySQL server, so it COULD be slower, right?(Maybe not in this case but in an general case) – user1287703 Mar 23 '12 at 08:35

1 Answers1

3
  1. Select * is evil
  2. It's almost always best to normalize your metadata in a separate table (allows you to use indexes, searches, joins, etc.)
Community
  • 1
  • 1
landons
  • 9,502
  • 3
  • 33
  • 46
  • is it then better to start 2 querys one for page data and one for metatags or to join them? – user1287703 Mar 23 '12 at 08:29
  • If you have multiple pages that need to be selected with a particular meta field, put that field in the pages table (for use with a join). Anything that only needs to be included when a page is requested in isolation, store that in the meta table, and use two queries on that request (you don't want as many queries as you have pages running on a single request...) – landons Mar 23 '12 at 09:42