Posts

Showing posts with the label query-optimization

How to optimise this MySQL query? Millions of Rows

How to optimise this MySQL query? Millions of Rows I have the following query: SELECT analytics.source AS referrer, COUNT(analytics.id) AS frequency, SUM(IF(transactions.status = 'COMPLETED', 1, 0)) AS sales FROM analytics LEFT JOIN transactions ON analytics.id = transactions.analytics WHERE analytics.user_id = 52094 GROUP BY analytics.source ORDER BY frequency DESC LIMIT 10 The analytics table has 60M rows and the transactions table has 3M rows. When I run an EXPLAIN on this query, I get: EXPLAIN +------+--------------+-----------------+--------+---------------------+-------------------+----------------------+---------------------------+----------+-----------+-------------------------------------------------+ | # id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | | +------+--------------+-----------------+-...

sybase ase deferred update mode

sybase ase deferred update mode I could use some help regarding the optimizer choices for the below update. I expected a direct update, not a deferred update. In real live this concerns a target table containing ~5M rows being updated from a smaller table with ~200k rows. The deferred update takes quit some time, also because the target table has about 60 columns. Any suggestions explaining this behavior are very welcome, including suggestions to improve performance of this query. The smaller table can easily be modified, changes to the target table have more impact as it is part of the product datamodel. Many thanks! Elroy select @@version --Adaptive Server Enterprise/15.5/EBF 18158 SMP ESD#2/P/X64/Windows Server/asear155/2514/64-bit/OPT/Wed Aug 25 05:39:57 2010 IF OBJECT_ID('test_target') IS NOT NULL DROP TABLE test_target GO CREATE TABLE test_target ( id numeric(15,0) IDENTITY NOT NULL, col1 numeric(15,0) NOT NULL, col2 char(15...