question

Axel Kohonen avatar image
0 Likes"
Axel Kohonen asked Axel Kohonen commented

Table query speed

Hi,

A few questions about the Table query execution speed, which do not seem to be documented anywhere.Please point me to the documentation if it exists.

  1. How does the Table.query command work when multiple criteria are given? It seems that the speed of the query depends (sometimes a lot) on the order of the criteria. E.g. first criteria being something like a general category (category = "food") and second e.g. weight on row (weight >= 50) does not give the same result as giving the criteria the other way around. This is obviously not visible with small tables, but if one has 10000+ rows then it can make a big difference.
  2. Do the later criteria check only the subset that the first criteria returns?
  3. Does ORDER BY always check all rows of the table or only the subset that the query returned?
  4. Is the table query faster with bundle tables?
  5. What does "optimize column for lookup" do and when should it be used?
  6. Can I optimize multiple columns for lookup?
  7. Does it even make sense to use Table.query for very large tables or should some other method be used?

Thank you!

Kind regards,

Axel

FlexSim 18.2.3
querysql queriestablespeed
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

anthony.johnson avatar image
1 Like"
anthony.johnson answered Axel Kohonen commented

1. The SQL engine's AND expression works like most other evaluators in that it stops evaluation if the left operand is false. This means that if your left operand effects a narrower filter, then it would naturally go faster because you are filtering things earlier and not needing to evaluate as many right operands.

2. As explained in 1, an AND will stop evaluation if the left operand is false, so technically yes, subsequent requirements are only evaluated on the subset whose left operand is true.

3. FlexSim's SQL engine works the same as most SQL engines. The execution happens in the following order:

  1. Filter (WHERE / ON) - It will traverse the source table(s) and create a filtered subset based on the ON and/or WHERE clauses.
  2. Aggregate (GROUP BY) - If there are aggregation functions in the SELECT clause or a GROUP BY clause, it will aggregate the filtered subset into a new subset, categorized by the GROUP BY.
  3. Filter Aggregation (HAVING) - If there is a HAVING clause, it will further filter the aggregated subset.
  4. Sort (ORDER BY) - Sorting is the last operation to be done. It is only done on the final subset.

4. We haven't done rigorous speed tests comparing tree table queries to bundle table queries. I would think that bundles are faster, primarily because bundle tables are more cache-friendly. But the amount of improvement is likely dependent on the situation.

5. The option "optimize column for lookup" only applies to bundle tables. It primarily allows you to use the getbundleindexedentries() command. While it can improve some performance with the query command, this only applies when using a join, and it only saves the time that the query would normally use to build a cross-index. So, at least for now, it's not a great improvement for Table.query().

6. Right now there's not really a direct way to optimize certain columns for lookup.

7. If you are essentially trying to run Table.query() to lookup a single row in a single table, lots and lots of times, then right now, Table.query() is probably not your best bet. I would suggest using the getbundleindexedentries() command. That said, the groundwork has been laid for us to make Table.query() faster in your scenario. We've already implemented an indexing mechanism that makes inner joins orders of magnitude faster. We just need to also use that same (or similar) indexing mechanism in a single-table-lookup scenario. So hopefully this will be an improvement in the not-too-distant future.

· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.