Foxpert Software Development & Consulting

Menu

Whitepapers
Downloads
Knowlbits
Guineu

2007-05May-16

Optimal slow

Optimizing queries in Visual FoxPro is often attributed with increasing speed. Years ago we've seen with the discussion about an index on DELETED() that this is not a universal rule. Optimizing queries can be quite a tricky thing. Here's a situation to think about. You have two tables A and B. The query returns all records from A and about half the records of B:

SELECT * FROM A ;
  JOIN B ON A.PK = B.FK ;
  WHERE SomeCondition.

SomeCondition is not optimized. So you think about optimizing the query by creating necessary indexes. Congratulations! You successfully reduced the amount of data that had to be transferred across the network.. and slowed down the query at the same time.

What seems to be an oxymoron at first is easily explained. When Visual FoxPro reads records in a loop, it never reads single records but a block of records. In the first case, Visual FoxPro has to scan sequentially through table B reading like a dozen of records with each read operation.

When you optimize the query, Visual FoxPro creates a map of hits. If there's one miss in a dozen hits, Visual FoxPro has to split the single read request of 12 records into two read requests of five and six records. The more records you filter out, the more fragments you have to read. In the end, you might end up with only 50% of the records, but require 600% percent more read operations to retrieve them.

Read operations across a network are expensive. They frequently map to a single network packet. Every additional packet adds overhead for protocol headers, adds delay due to network latency and adds workload to the network for routing and filtering packets. Congratulations!

Previous KnowlBits

RSS

October 2009 (2)

September 2009 (1)

August 2009 (4)

July 2009 (2)

June 2009 (2)

May 2009 (1)

April 2009 (1)

March 2009 (1)

August 2008 (1)

July 2008 (2)

May 2008 (1)

April 2008 (2)

January 2008 (2)

December 2007 (2)

November 2007 (2)

October 2007 (1)

September 2007 (1)

August 2007 (5)

July 2007 (4)

May 2007 (6)

March 2007 (3)

February 2007 (7)

January 2007 (6)

November 2006 (1)

October 2006 (3)

September 2006 (10)

June 2006 (2)

May 2006 (6)

April 2006 (1)


Impressum Kontakt Contact