AlexTatiyants / pev

Postgres Explain Visualizer
MIT License
2.77k stars 192 forks source link

SyntaxError: Unexpected token #7

Closed mrmuskrat closed 8 years ago

mrmuskrat commented 8 years ago

I get a JavaScript exception when I use anything other than a sample plan (by clicking the "CREATE A SAMPLE PLAN" link). I started psql with -X and the exact query to produce the plan was: EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS, FORMAT JSON) SELECT datname, pid, usename, application_name, client_addr, client_hostname, client_port, query, state FROM pg_stat_activity;

I clicked the "NEW PLAN" button (URL: http://tatiyants.com/pev/#/plans/new) and filled out the following (rearranged in an attempt to make it more readable).

name: pg_stat_activity SQL query: SELECT datname, pid, usename, application_name, client_addr, client_hostname, client_port, query, state FROM pg_stat_activity; execution plan: [ { "Plan": { "Node Type": "Nested Loop", "Join Type": "Inner", "Startup Cost": 1.16, "Total Cost": 2.67, "Plan Rows": 1, "Plan Width": 296, "Actual Startup Time": 0.132, "Actual Total Time": 0.177, "Actual Rows": 16, "Actual Loops": 1, "Output": ["d.datname", "s.pid", "u.rolname", "s.application_name", "s.client_addr", "s.client_hostname", "s.client_port", "s.query", "s.state"], "Shared Hit Blocks": 33, "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, "I/O Read Time": 0.000, "I/O Write Time": 0.000, "Plans": [ { "Node Type": "Hash Join", "Parent Relationship": "Outer", "Join Type": "Inner", "Startup Cost": 1.02, "Total Cost": 2.41, "Plan Rows": 1, "Plan Width": 236, "Actual Startup Time": 0.122, "Actual Total Time": 0.133, "Actual Rows": 16, "Actual Loops": 1, "Output": ["s.pid", "s.application_name", "s.client_addr", "s.client_hostname", "s.client_port", "s.query", "s.state", "s.datid", "u.rolname"], "Hash Cond": "(s.usesysid = u.oid)", "Shared Hit Blocks": 1, "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, "I/O Read Time": 0.000, "I/O Write Time": 0.000, "Plans": [ { "Node Type": "Function Scan", "Parent Relationship": "Outer", "Function Name": "pg_stat_get_activity", "Schema": "pg_catalog", "Alias": "s", "Startup Cost": 0.00, "Total Cost": 1.00, "Plan Rows": 100, "Plan Width": 176, "Actual Startup Time": 0.088, "Actual Total Time": 0.089, "Actual Rows": 16, "Actual Loops": 1, "Output": ["s.datid", "s.pid", "s.usesysid", "s.application_name", "s.state", "s.query", "s.waiting", "s.xact_start", "s.query_start", "s.backend_start", "s.state_change", "s.client_addr", "s. "Function Call": "pg_stat_get_activity(NULL::integer)", "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, "I/O Read Time": 0.000, "I/O Write Time": 0.000 }, { "Node Type": "Hash", "Parent Relationship": "Inner", "Startup Cost": 1.01, "Total Cost": 1.01, "Plan Rows": 1, "Plan Width": 68, "Actual Startup Time": 0.016, "Actual Total Time": 0.016, "Actual Rows": 14, "Actual Loops": 1, "Output": ["u.rolname", "u.oid"], "Hash Buckets": 1024, "Hash Batches": 1, "Original Hash Batches": 1, "Peak Memory Usage": 2, "Shared Hit Blocks": 1, "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, "I/O Read Time": 0.000, "I/O Write Time": 0.000, "Plans": [ { "Node Type": "Seq Scan", "Parent Relationship": "Outer", "Relation Name": "pg_authid", "Schema": "pg_catalog", "Alias": "u", "Startup Cost": 0.00, "Total Cost": 1.01, "Plan Rows": 1, "Plan Width": 68, "Actual Startup Time": 0.008, "Actual Total Time": 0.008, "Actual Rows": 14, "Actual Loops": 1, "Output": ["u.rolname", "u.oid"], "Shared Hit Blocks": 1, "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, "I/O Read Time": 0.000, "I/O Write Time": 0.000 } ] } ] }, { "Node Type": "Index Scan", "Parent Relationship": "Inner", "Scan Direction": "Forward", "Index Name": "pg_database_oid_index", "Relation Name": "pg_database", "Schema": "pg_catalog", "Alias": "d", "Startup Cost": 0.13, "Total Cost": 0.25, "Plan Rows": 1, "Plan Width": 68, "Actual Startup Time": 0.001, "Actual Total Time": 0.002, "Actual Rows": 1, "Actual Loops": 16, "Output": ["d.datname", "d.oid"], "Index Cond": "(d.oid = s.datid)", "Rows Removed by Index Recheck": 0, "Shared Hit Blocks": 32, "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, "I/O Read Time": 0.000, "I/O Write Time": 0.000 } ] }, "Planning Time": 0.389, "Triggers": [ ], "Execution Time": 0.248 } ]

tatiyants.com-1453831227573.txt

AlexTatiyants commented 8 years ago

the query plan is not valid JSON. You'll get a bunch of validation errors if you try it with JSON Formatter

mrmuskrat commented 8 years ago

Apparently you need to set \x on before calling explain or long lines get truncated. Alternately, write the output to a file.

mrmuskrat commented 8 years ago

Closing as this was a problem with my usage of psql.