One of Fregas' clients was frustrated with their ColdFusion-based inventory & accounting system. They had paid another company with "a team of specialized ColdFusion experts" to custom-build their system, but were having problems as the system kept getting slower and slower. They were especially annoyed with this problem because they were sold on the fact that ColdFusion was very fast. While "speeding up" the system, Fregas came across quite possibly the slowest way to do a table record count ...

<!--                          -->
<!-- Calculate Bookings Count -->
<!--                          -->
<cfquery name="q1" datasource="#Request.InitechDatabase#">
  SELECT * FROM Clients 
</cfquery>
<cfloop query="q1"> 
  <cfquery name="q2" datasource="#Request.InitechDatabase#">
    SELECT * FROM Bookings WHERE Client_Num = '#Client_Num#'
  </cfquery>
  <cfif q2.recordcount GT 0>
    <cfloop query="q2">
      <cfif q2.bookings_active_indicator IS "Y">
        <cfset bookingsCount = bookingsCount + 1>
      </cfif>
    </cfloop>
  </cfif>
</cfloop>