pghero 3.3.4 → 3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/app/controllers/pg_hero/home_controller.rb +8 -2
- data/lib/pghero/methods/explain.rb +3 -2
- data/lib/pghero/methods/query_stats.rb +1 -1
- data/lib/pghero/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be29c474a85a6d881dba5ab5a3b8ae273d62553fac0eeeef6c7a08f2087a4da1
|
4
|
+
data.tar.gz: a8637f122ec9946fb217bf6d7ab63b9aff2160de28c05bf054a25ce7d874c53c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca6814ef570346653fa61963853839faeaa7c5a1c54224641cf709c303cc4b438e081b6b800eeb38c2167cba373c9734d1645ca7dcd7429b3c925b4420d83f31
|
7
|
+
data.tar.gz: c43a0efe62ab9be1b894335719294ed6328201c01645293ef4ca7c93ad9b0081486720d3229139f485ae7dc87ebc236b1a5391294c8f1c7c46114d58d847bb3d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -8,7 +8,7 @@ A performance dashboard for Postgres
|
|
8
8
|
|
9
9
|
:tangerine: Battle-tested at [Instacart](https://www.instacart.com/opensource)
|
10
10
|
|
11
|
-
[![Build Status](https://github.com/ankane/pghero/workflows/build/badge.svg?branch=master)](https://github.com/ankane/pghero/actions)
|
11
|
+
[![Build Status](https://github.com/ankane/pghero/workflows/build/badge.svg?branch=master)](https://github.com/ankane/pghero/actions)
|
12
12
|
|
13
13
|
## Documentation
|
14
14
|
|
@@ -292,12 +292,14 @@ module PgHero
|
|
292
292
|
# need to prevent CSRF and DoS
|
293
293
|
if request.post? && @query.present?
|
294
294
|
begin
|
295
|
+
generic_plan = @database.server_version_num >= 160000 && @query.include?("$1")
|
296
|
+
|
295
297
|
explain_options =
|
296
298
|
case params[:commit]
|
297
299
|
when "Analyze"
|
298
300
|
{analyze: true}
|
299
301
|
when "Visualize"
|
300
|
-
if @explain_analyze_enabled
|
302
|
+
if @explain_analyze_enabled && !generic_plan
|
301
303
|
{analyze: true, costs: true, verbose: true, buffers: true, format: "json"}
|
302
304
|
else
|
303
305
|
{costs: true, verbose: true, format: "json"}
|
@@ -306,6 +308,8 @@ module PgHero
|
|
306
308
|
{}
|
307
309
|
end
|
308
310
|
|
311
|
+
explain_options[:generic_plan] = true if generic_plan
|
312
|
+
|
309
313
|
if explain_options[:analyze] && !@explain_analyze_enabled
|
310
314
|
render_text "Explain analyze not enabled", status: :bad_request
|
311
315
|
return
|
@@ -319,8 +323,10 @@ module PgHero
|
|
319
323
|
@error =
|
320
324
|
if message == "Unsafe statement"
|
321
325
|
"Unsafe statement"
|
322
|
-
elsif message.start_with?("PG::
|
326
|
+
elsif message.start_with?("PG::UndefinedParameter")
|
323
327
|
"Can't explain queries with bind parameters"
|
328
|
+
elsif message.include?("EXPLAIN options ANALYZE and GENERIC_PLAN cannot be used together")
|
329
|
+
"Can't analyze queries with bind parameters"
|
324
330
|
elsif message.start_with?("PG::SyntaxError")
|
325
331
|
"Syntax error with query"
|
326
332
|
elsif message.start_with?("PG::QueryCanceled")
|
@@ -12,7 +12,7 @@ module PgHero
|
|
12
12
|
if (sql.sub(/;\z/, "").include?(";") || sql.upcase.include?("COMMIT")) && !explain_safe?
|
13
13
|
raise ActiveRecord::StatementInvalid, "Unsafe statement"
|
14
14
|
end
|
15
|
-
explanation =
|
15
|
+
explanation = execute("EXPLAIN #{sql}").map { |v| v["QUERY PLAN"] }.join("\n")
|
16
16
|
end
|
17
17
|
|
18
18
|
explanation
|
@@ -20,11 +20,12 @@ module PgHero
|
|
20
20
|
|
21
21
|
# TODO rename to explain in 4.0
|
22
22
|
# note: this method is not affected by the explain option
|
23
|
-
def explain_v2(sql, analyze: nil, verbose: nil, costs: nil, settings: nil, buffers: nil, wal: nil, timing: nil, summary: nil, format: "text")
|
23
|
+
def explain_v2(sql, analyze: nil, verbose: nil, costs: nil, settings: nil, generic_plan: nil, buffers: nil, wal: nil, timing: nil, summary: nil, format: "text")
|
24
24
|
options = []
|
25
25
|
add_explain_option(options, "ANALYZE", analyze)
|
26
26
|
add_explain_option(options, "VERBOSE", verbose)
|
27
27
|
add_explain_option(options, "SETTINGS", settings)
|
28
|
+
add_explain_option(options, "GENERIC_PLAN", generic_plan)
|
28
29
|
add_explain_option(options, "COSTS", costs)
|
29
30
|
add_explain_option(options, "BUFFERS", buffers)
|
30
31
|
add_explain_option(options, "WAL", wal)
|
@@ -319,7 +319,7 @@ module PgHero
|
|
319
319
|
end
|
320
320
|
|
321
321
|
def explainable?(query)
|
322
|
-
query =~ /select/i && !query.include?("?)") && !query.include?("= ?") && !query.include?("$1") && query !~ /limit \?/i
|
322
|
+
query =~ /select/i && (server_version_num >= 160000 || (!query.include?("?)") && !query.include?("= ?") && !query.include?("$1") && query !~ /limit \?/i))
|
323
323
|
end
|
324
324
|
|
325
325
|
# removes comments
|
data/lib/pghero/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pghero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|