Does query plan optimizer works well with joined/filtered table-valued functions?

In this case, it’s an “inline table valued function” The optimiser simply expands (unnests) it if it’s useful (or view). If the function is treated as “black box” by the outer query, the quickest way is to compare IO shown in SSMS vs IO in profiler. Profler captures “black box” IO that SSMS does not. … Read more

How to avoid “Using temporary” in many-to-many queries?

Here’s a simplified example I did for a similar performance related question sometime ago that takes advantage of innodb clustered primary key indexes (obviously only available with innodb !!) http://dev.mysql.com/doc/refman/5.0/en/innodb-index-types.html http://www.xaprb.com/blog/2006/07/04/how-to-exploit-mysql-index-optimizations/ You have 3 tables: category, product and product_category as follows: drop table if exists product; create table product ( prod_id int unsigned not null … Read more

SELECT DISTINCT is slower than expected on my table in PostgreSQL

While there is no index skip scan in Postgres yet, emulate it: WITH RECURSIVE cte AS ( ( — parentheses required SELECT product_id FROM tickers ORDER BY 1 LIMIT 1 ) UNION ALL SELECT l.* FROM cte c CROSS JOIN LATERAL ( SELECT product_id FROM tickers t WHERE t.product_id > c.product_id — lateral reference ORDER … Read more