0

我在COGNOS中有一个查询,它会获取大量数据。由于执行时间会更长,我想微调我的查询。每个人都知道查询中的 WHERE 子句将首先执行。

我的疑问是执行查询时会先发生哪个?

是先建立查询中的JOIN还是先执行WHERE子句?

如果先建立 JOIN,我应该先指定DIMENSION的过滤器,否则我应该先指定FACT的过滤器。

请解释一下。

提前致谢。

4

2 回答 2

1

The idea of SQL is that it is a high level declarative language, meaning you tell it what results you want rather than how to get them. There are exceptions to this in various SQL implementations such as hints in Oracle to use a specific index etc, but as a general rule this holds true.

Behind the scenes the optimiser for your RDBMS implements relational algebra to do a cost based estimate of the different potential execution plans and select the one that it predicts will be the most efficient. The great thing about this is that you do not need to worry what order you write your where clauses in etc, so long as all of the information is there the optimiser should pick the most efficient plan.

That being said there are often things that you can so on the database to improve query performance such as building indexes on columns in large tables that are often used in filtering criteria or joins.

Another consideration is whether you can use parallel hints to speed up your run time but this will depend on your query, the execution plan that is being used, the RDBMS you are using and the hardware it is running on.

If you post the query syntax and what RDBMS you are using we can check if there is anything obvious that could be amended in this case.

于 2013-07-02T16:51:12.747 回答
1

The order of filters definitely does not matter. The optimizer will take care of that.

As for filtering on the fact or dimension table - do you mean you are exposing the same field in your Cognos model for each (ex ProductID from both fact and Product dimension)? If so, that is not recommended. Generally speaking, you should expose the dimension field only.

This is more of a question about your SQL environment, though. I would export the SQL generated by Cognos from within Report Studio (Tools -> Show Generated SQL). From there, hopefully you are able to work with a good DBA to see if there are any obvious missing indexes, etc in your tables.

There's not a whole lot of options within Cognos to change the SQL generation. The prior poster mentions hints, which could work if writing native SQL, but that is a concept not known to Cognos. Really, all you can do is change the implict/explict join syntax which just controls whether the join happens in an ON statement or in the WHERE. Although the WHERE side is pretty ugly it generally compiles the same as ON.

于 2013-07-02T17:49:29.950 回答