Skip to content

Instantly share code, notes, and snippets.

@felixge
Created August 13, 2020 08:30
Show Gist options
  • Save felixge/0baa45ea6782ea4af191b9ef70584043 to your computer and use it in GitHub Desktop.
Save felixge/0baa45ea6782ea4af191b9ef70584043 to your computer and use it in GitHub Desktop.
{
"flameExplain": "Go to flame-explain.com and paste this JSON in the Input tab.",
"input": {
"plan": "[\n {\n \"Plan\": {\n \"Node Type\": \"Function Scan\",\n \"Parallel Aware\": false,\n \"Function Name\": \"generate_series\",\n \"Schema\": \"pg_catalog\",\n \"Alias\": \"generate_series\",\n \"Startup Cost\": 0.00,\n \"Total Cost\": 10.00,\n \"Plan Rows\": 1000,\n \"Plan Width\": 4,\n \"Actual Startup Time\": 194.503,\n \"Actual Total Time\": 331.185,\n \"Actual Rows\": 1500000,\n \"Actual Loops\": 1,\n \"Output\": [\"generate_series\"],\n \"Function Call\": \"generate_series(1, 1500000)\",\n \"Shared Hit Blocks\": 0,\n \"Shared Read Blocks\": 0,\n \"Shared Dirtied Blocks\": 0,\n \"Shared Written Blocks\": 0,\n \"Local Hit Blocks\": 0,\n \"Local Read Blocks\": 0,\n \"Local Dirtied Blocks\": 0,\n \"Local Written Blocks\": 0,\n \"Temp Read Blocks\": 0,\n \"Temp Written Blocks\": 0\n },\n \"Planning Time\": 0.046,\n \"Triggers\": [\n ],\n \"Execution Time\": 468.095\n }\n]",
"sql": "/** The query below does two scans on the CTE foo. The first is triggered by the\nEXIST predicate and only reads the first row and pays the pg_sleep(0.1) cost.\nThe second scan comes from the main query, which also reads row one, but\ndoesn't pay the sleep cost again, since the tuple has already been stored in\nmemory. However, the second scan has to pay the cost of pg_sleep(0.2).\npg_sleep(0.3) is never executed because the main query has a limit of 2.\n\nThis causes EXPLAIN ANALYZE to produce an output where a lot of the numbers\ndon't add up due to including the costs of the CTE InitPlan and Filter InitPlan\nmore than once. FlameExplain is currently the only tool that can correctly\nadjust such a plan to make sense. */\nEXPLAIN (ANALYZE, FORMAT JSON)\nWITH foo AS (\n SELECT 1 as i, pg_sleep(0.1)\n UNION ALL\n SELECT 2 as i, pg_sleep(0.2)\n UNION ALL\n SELECT 3 as i, pg_sleep(0.3)\n)\nSELECT * FROM foo WHERE EXISTS (SELECT * FROM foo) LIMIT 2"
},
"favorites": [
"ID",
"Label",
"Actual Rows"
],
"collapsed": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment