pghero 3.3.4 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2332e2a4f7b9bd25d972ec1f06635dfc43676412c5be4147e3a7e3dc8effa213
4
- data.tar.gz: 1a24e423a0d8749d69eb938eaa27db1beed974d1a058e6ae6331badeae9c4d59
3
+ metadata.gz: be29c474a85a6d881dba5ab5a3b8ae273d62553fac0eeeef6c7a08f2087a4da1
4
+ data.tar.gz: a8637f122ec9946fb217bf6d7ab63b9aff2160de28c05bf054a25ce7d874c53c
5
5
  SHA512:
6
- metadata.gz: b19ca11ceee2f44bbcdec49e14f0653df6efc740e4fbd710700a03254ac8d40db84690409a731c06359d547934d401615925e88df317ccae4137eecefcfe8ddf
7
- data.tar.gz: b6c0069a0e34ecd66d359aff9226fe678ccc15d55b1ad0e70f421a7fa9b9a2113d7eb31cc30d69364489fa1e10e2b5d6d0e48ada03d15e79aff5ba9dda350659
6
+ metadata.gz: ca6814ef570346653fa61963853839faeaa7c5a1c54224641cf709c303cc4b438e081b6b800eeb38c2167cba373c9734d1645ca7dcd7429b3c925b4420d83f31
7
+ data.tar.gz: c43a0efe62ab9be1b894335719294ed6328201c01645293ef4ca7c93ad9b0081486720d3229139f485ae7dc87ebc236b1a5391294c8f1c7c46114d58d847bb3d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 3.4.0 (2023-11-28)
2
+
3
+ - Added support for explaining normalized queries with Postgres 16
4
+ - Added Docker image for `linux/arm64`
5
+
1
6
  ## 3.3.4 (2023-09-05)
2
7
 
3
8
  - Fixed support for aliases in config file
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) [![Docker Pulls](https://img.shields.io/docker/pulls/ankane/pghero)](https://hub.docker.com/r/ankane/pghero)
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::ProtocolViolation: ERROR: bind message supplies 0 parameters")
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 = select_all("EXPLAIN #{sql}").map { |v| v[:"QUERY PLAN"] }.join("\n")
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
@@ -1,3 +1,3 @@
1
1
  module PgHero
2
- VERSION = "3.3.4"
2
+ VERSION = "3.4.0"
3
3
  end
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.3.4
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-09-05 00:00:00.000000000 Z
11
+ date: 2023-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord