Tech Tip: Reduce Server Requests with Optimized Queries
PRODUCT: 4D | VERSION: 18 | PLATFORM: Mac & Win
Published On: June 18, 2020
Each query made will perform a server request to generate the results. Many queries and processes can be optimized down to a single request.
A typical example is with the use of the QUERY or QUERY SELECTION command directly after another. In this case these queries can be combined into one request using the continue query flag or one of the calls can be removed completely.
There are alot of other possible ways where some queries may not be optimized, but it can be very helpful to start out with searching for uses of QUERY SELECTION which is typically used after a query has already been performed and can be quickly searched for using Find in Design.
Example 1 - Using the continue query flag:
// The following three lines are three separate requests QUERY([Table_1];[Table_1]Count>5) QUERY SELECTION([Table_1];[Table_1]Boolean=True) QUERY SELECTION([Table_1];[Table_1]Started=True) // The following three lines return the same results in one request QUERY([Table_1];[Table_1]Count>5;*) QUERY ([Table_1];[Table_1]Boolean=True;*) QUERY ([Table_1];[Table_1]Started=True) |
Example 2 - Improving queries in conditional statements:
// In the case that $vAll is False there are three requests made QUERY ([Table_1];[Table_1]Started=True) QUERY SELECTION([Table_1];[Table_1]Boolean=True) If($vAll=False) QUERY SELECTION([Table_1];[Table_1]Count>10) End if // The following will return the same results and make a single request regardless of the condition. If($vAll=False) QUERY ([Table_1];[Table_1]Count>10;*) End if QUERY ([Table_1];[Table_1]Started=True;*) QUERY ([Table_1];[Table_1]Boolean=True) |