Does a large number of very simple sql queries affect performance?


I have search filters. Each filter/attribute have own values I need to show.

<?php foreach(getAdditionalFilters() as $attributeName => $filterData): ?>
  <?php showLiCheckBoxes($attributeName); ?>
<?php endforeach; ?>

There are two ways how to display filters:


function showLiCheckBoxes($attribute,$checked=null){
    $CI = get_instance();
    $allAttrOptions = $CI->helper_model->getAttrOptions($attribute);
    foreach($allAttrOptions as $key => $option){
      //print html of inputs like <li><input type='checkox' value='{$option['optionId']}...

function getAttrOptions($attrCode){
      $sql = "SELECT option_id as optionId, label FROM eav_attribute_option
              INNER JOIN eav_attribute USING(attr_id)
              WHERE code='$attrCode'";
      $query = $this->db->prepare($sql);
      return $query->fetchAll();


function showLiCheckBoxes($attribute,$checked=null){
    foreach(Attributes::${$attribute} as $key => $value){
      //print html of inputs like <li><input type='checkox' value='{$option['optionId']}...

class Attributes

    public static $education        = array(0 => 'No answer',
                                            1 => 'High school',
                                            2 => 'Some college',
                                            3 => 'In college',
                                            4 => 'College graduate',
                                            5 => 'Grad / professional school',
                                            6 => 'Post grad');
     public static $...

So in the first way attributes options are stored in database and as you can see for each attribute extra query is made. In the second way attributes options are stored in array.

I am not asking which way is correct because there are some other facts not wrote here. What I am asking is just that if 20 extra very simple queries for table eav_attribute_option with only 500 rows could make any performance impact. Should I care about it or is the query I wrote here so simple and table is so small that it won't make any difference at all?

Of course I could make this also with 1 query, but this is not the question again. I was asking myself if so many extra requests to sql server could be a bad thing, not the query itself.

You have to profile it to know if it takes too long for your scenario.

Every query has an overhead, regardless of the number of rows returned.
So, in general, one query that returns 20 rows is better than 20 queries that return one row each.