dalibo / pev2

Postgres Explain Visualizer 2
https://explain.dalibo.com
PostgreSQL License
2.67k stars 130 forks source link

Visualization bug #608

Closed robert-sjoblom closed 3 months ago

robert-sjoblom commented 1 year ago

Hi,

I love the tool, thank you so much for maintaining it. Today we found a (minor) viz bug. The following query:

[
  {
    "Plan": {
      "Node Type": "CTE Scan",
      "Parallel Aware": false,
      "Async Capable": false,
      "CTE Name": "c",
      "Alias": "c",
      "Startup Cost": 77.40,
      "Total Cost": 78.62,
      "Plan Rows": 61,
      "Plan Width": 81,
      "Actual Startup Time": 0.005,
      "Actual Total Time": 2.089,
      "Actual Rows": 11,
      "Actual Loops": 1,
      "Output": ["c.company_id", "c.id", "c.entity_processed", "c.relation"],
      "Shared Hit Blocks": 0,
      "Shared Read Blocks": 5,
      "Shared Dirtied Blocks": 0,
      "Shared Written Blocks": 0,
      "Local Hit Blocks": 0,
      "Local Read Blocks": 0,
      "Local Dirtied Blocks": 0,
      "Local Written Blocks": 0,
      "Temp Read Blocks": 0,
      "Temp Written Blocks": 0,
      "Plans": [
        {
          "Node Type": "Recursive Union",
          "Parent Relationship": "InitPlan",
          "Subplan Name": "CTE c",
          "Parallel Aware": false,
          "Async Capable": false,
          "Startup Cost": 0.00,
          "Total Cost": 77.40,
          "Plan Rows": 61,
          "Plan Width": 85,
          "Actual Startup Time": 0.003,
          "Actual Total Time": 2.081,
          "Actual Rows": 11,
          "Actual Loops": 1,
          "Shared Hit Blocks": 0,
          "Shared Read Blocks": 5,
          "Shared Dirtied Blocks": 0,
          "Shared Written Blocks": 0,
          "Local Hit Blocks": 0,
          "Local Read Blocks": 0,
          "Local Dirtied Blocks": 0,
          "Local Written Blocks": 0,
          "Temp Read Blocks": 0,
          "Temp Written Blocks": 0,
          "Plans": [
            {
              "Node Type": "Result",
              "Parent Relationship": "Outer",
              "Parallel Aware": false,
              "Async Capable": false,
              "Startup Cost": 0.00,
              "Total Cost": 0.01,
              "Plan Rows": 1,
              "Plan Width": 81,
              "Actual Startup Time": 0.002,
              "Actual Total Time": 0.002,
              "Actual Rows": 1,
              "Actual Loops": 1,
              "Output": ["'COMPANY_ID'::character varying", "'UUID'::uuid", "false", "'parent'::text"],
              "Shared Hit Blocks": 0,
              "Shared Read Blocks": 0,
              "Shared Dirtied Blocks": 0,
              "Shared Written Blocks": 0,
              "Local Hit Blocks": 0,
              "Local Read Blocks": 0,
              "Local Dirtied Blocks": 0,
              "Local Written Blocks": 0,
              "Temp Read Blocks": 0,
              "Temp Written Blocks": 0
            },
            {
              "Node Type": "Nested Loop",
              "Parent Relationship": "Inner",
              "Parallel Aware": false,
              "Async Capable": false,
              "Join Type": "Inner",
              "Startup Cost": 0.56,
              "Total Cost": 7.62,
              "Plan Rows": 6,
              "Plan Width": 85,
              "Actual Startup Time": 1.032,
              "Actual Total Time": 1.035,
              "Actual Rows": 5,
              "Actual Loops": 2,
              "Output": ["ed.company_id", "ed.dependency_entity_id", "ed.entity_processed", "'child'::text"],
              "Inner Unique": false,
              "Shared Hit Blocks": 0,
              "Shared Read Blocks": 5,
              "Shared Dirtied Blocks": 0,
              "Shared Written Blocks": 0,
              "Local Hit Blocks": 0,
              "Local Read Blocks": 0,
              "Local Dirtied Blocks": 0,
              "Local Written Blocks": 0,
              "Temp Read Blocks": 0,
              "Temp Written Blocks": 0,
              "Plans": [
                {
                  "Node Type": "WorkTable Scan",
                  "Parent Relationship": "Outer",
                  "Parallel Aware": false,
                  "Async Capable": false,
                  "CTE Name": "c",
                  "Alias": "c_1",
                  "Startup Cost": 0.00,
                  "Total Cost": 0.22,
                  "Plan Rows": 1,
                  "Plan Width": 16,
                  "Actual Startup Time": 0.002,
                  "Actual Total Time": 0.002,
                  "Actual Rows": 0,
                  "Actual Loops": 2,
                  "Output": ["c_1.company_id", "c_1.id", "c_1.entity_processed", "c_1.relation"],
                  "Filter": "(c_1.id = 'UUID'::uuid)",
                  "Rows Removed by Filter": 5,
                  "Shared Hit Blocks": 0,
                  "Shared Read Blocks": 0,
                  "Shared Dirtied Blocks": 0,
                  "Shared Written Blocks": 0,
                  "Local Hit Blocks": 0,
                  "Local Read Blocks": 0,
                  "Local Dirtied Blocks": 0,
                  "Local Written Blocks": 0,
                  "Temp Read Blocks": 0,
                  "Temp Written Blocks": 0
                },
                {
                  "Node Type": "Index Scan",
                  "Parent Relationship": "Inner",
                  "Parallel Aware": false,
                  "Async Capable": false,
                  "Scan Direction": "Forward",
                  "Index Name": "entity_dependencies_pkey",
                  "Relation Name": "entity_dependencies",
                  "Schema": "assimilator",
                  "Alias": "ed",
                  "Startup Cost": 0.56,
                  "Total Cost": 7.33,
                  "Plan Rows": 6,
                  "Plan Width": 69,
                  "Actual Startup Time": 2.055,
                  "Actual Total Time": 2.058,
                  "Actual Rows": 10,
                  "Actual Loops": 1,
                  "Output": ["ed.company_id", "ed.entity_id", "ed.dependency_entity_id", "ed.created", "ed.\"timestamp\"", "ed.entity_processed", "ed.entity_dependency_processed", "ed.relation_type"],
                  "Index Cond": "(((ed.company_id)::text = 'COMPANY_ID'::text) AND (ed.entity_id = 'UUID'::uuid))",
                  "Rows Removed by Index Recheck": 0,
                  "Shared Hit Blocks": 0,
                  "Shared Read Blocks": 5,
                  "Shared Dirtied Blocks": 0,
                  "Shared Written Blocks": 0,
                  "Local Hit Blocks": 0,
                  "Local Read Blocks": 0,
                  "Local Dirtied Blocks": 0,
                  "Local Written Blocks": 0,
                  "Temp Read Blocks": 0,
                  "Temp Written Blocks": 0
                }
              ]
            }
          ]
        }
      ]
    },
    "Query Identifier": 8747393158318922603,
    "Planning": {
      "Shared Hit Blocks": 9,
      "Shared Read Blocks": 0,
      "Shared Dirtied Blocks": 0,
      "Shared Written Blocks": 0,
      "Local Hit Blocks": 0,
      "Local Read Blocks": 0,
      "Local Dirtied Blocks": 0,
      "Local Written Blocks": 0,
      "Temp Read Blocks": 0,
      "Temp Written Blocks": 0
    },
    "Planning Time": 0.272,
    "Triggers": [
    ],
    "Execution Time": 2.133
  }
]

Could probably look a little bit better. Maybe. I figured I'd mention it, at least. It's not terrible.

pgiraud commented 1 year ago

Thanks for the report. This is indeed a bug. Could this be due to the "recursive union" node type? I'll check. Thanks again.

pgiraud commented 1 year ago

I understand what happens. The blue fat line is actually linking nodes #2 and #5. But because they are vertically aligned (at first display) and because links are always connecting from bottom of source node to top of target node, we have this weird drawing.

Playing a bit with which nodes are expanded, we can have a better understanding.

Screenshot from 2023-10-25 11-50-50

I'm afraid, this will be painful to properly fix.