Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ortutay23andme
Last active March 13, 2018 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ortutay23andme/12f03767db13343ee797c328a4d78c9c to your computer and use it in GitHub Desktop.
Save ortutay23andme/12f03767db13343ee797c328a4d78c9c to your computer and use it in GitHub Desktop.
SELECT
<values>
FROM
table_1,
(SELECT
id_1,
id_2,
<values>
FROM
table_3
WHERE
id_1 = {query_input_id} -- part of PK
AND <conditions> -- NOT part of PK
) AS subquery,
table_1_again
WHERE
id_2 NOT IN ( -- Filter out some values we don't want
SELECT
id_2
FROM
table_4
WHERE
id_1 = {query_input_id} -- part of PK
AND <condition> - NOT part of PK
) AND
table_4.id_2 = table_2.id AND
-- This hash join takes a long time. `subquery` is fairly
-- slow as it scans a few million records, and takes ~1s
-- to execute on it's own. This causes problems under
-- medium loads, eg. above 5qps
subquery.id_2 = table_1.id AND
table_1_again.field1 = 'varchar_filter_value' AND -- part of PK
table_1_again.field2 = 'another_varchar_filter_value' AND -- park of PK
table_1_again.field3 <> 'yet_another_varchar_filter_value' AND -- NOT part of PK
table_1.field1 = 'more_varchar_filters' AND -- part of PK
table_1.field2 = 'even_move_varchar_filters' AND -- part of PK
table_1.field3 <= 0.1 -- NOT part of pk
GROUP BY <columns>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment