pgdexter 0.3.10 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c604783bd2ae16f3bb648176f96664b31fb6ac50a0094e3d34df195e0a4bb9ee
4
- data.tar.gz: 299487f0880aa486c2678063f1f6bed4fc2398603b5fd9f2ebeb1c27b31cfb26
3
+ metadata.gz: 62ad383008579d8dbe952b3f96c827e01aa198c0eb74b3b884188472459b34b8
4
+ data.tar.gz: b77596742f0e13bb058354edcd901d1e93ec94f61bf6a695957c51fe9c7e41dc
5
5
  SHA512:
6
- metadata.gz: 3cbec0f51a8b884d468c92ebca35a47267b82c30c86b281052ae15cd25aa3499d9ad26b4c27fb1c8232a8ecce28bfbf656a44a099d5e28bea6ccc9523f01abe4
7
- data.tar.gz: 8a72520c058109b0f63c41efe79bc91c174fffdca423940c8201a28e94bd4465d4110d9918ba39c505b0fc674ce6e819108d4837ff416f5befaaff9c2bdff4e9
6
+ metadata.gz: 1b5f18ce901729f9e22d4222b0ba7ee498be18edb7897221c28069f8beceb65058342c47e9211ce94814d04b380387b95506722b1568a1d44b4d3c8386beeb17
7
+ data.tar.gz: fa51ae2cde49dfcf9fc181a30bda4941c2ea01f1186fdd6a8cd002059a71c4b3341686cd62f2d1366874c941b92db1a4f74a6abd272baa66063907602e1376c5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.4.0 (2022-07-27)
2
+
3
+ - Added support for pg_query 2
4
+ - Switched to monotonic time
5
+ - Dropped support for Ruby < 2.5
6
+
1
7
  ## 0.3.10 (2021-03-25)
2
8
 
3
9
  - Require pg_query < 2
data/README.md CHANGED
@@ -12,8 +12,8 @@ First, install [HypoPG](https://github.com/HypoPG/hypopg) on your database serve
12
12
 
13
13
  ```sh
14
14
  cd /tmp
15
- curl -L https://github.com/HypoPG/hypopg/archive/1.2.0.tar.gz | tar xz
16
- cd hypopg-1.2.0
15
+ curl -L https://github.com/HypoPG/hypopg/archive/1.3.1.tar.gz | tar xz
16
+ cd hypopg-1.3.1
17
17
  make
18
18
  make install # may need sudo
19
19
  ```
@@ -32,7 +32,7 @@ And install the command line tool with:
32
32
  gem install pgdexter
33
33
  ```
34
34
 
35
- The command line tool is also available as a [Linux package](guides/Linux.md).
35
+ The command line tool is also available with [Docker](#docker), [Homebrew](#homebrew), or as a [Linux package](guides/Linux.md).
36
36
 
37
37
  ## How to Use
38
38
 
@@ -190,7 +190,37 @@ dexter --log-sql --log-level debug2
190
190
 
191
191
  ## Hosted Postgres
192
192
 
193
- Some hosted providers like Amazon RDS and Heroku do not support the HypoPG extension, which Dexter needs to run. See [how to use Dexter](guides/Hosted-Postgres.md) in these cases.
193
+ Some hosted providers like Amazon RDS and Heroku do not support the HypoPG extension, which Dexter needs to run. See [how to use Dexter](guides/Hosted-Postgres.md) in these cases. To request the extension:
194
+
195
+ - Amazon RDS - follow the instructions on [this page](https://aws.amazon.com/rds/postgresql/faqs/)
196
+ - Google Cloud SQL - star the [feature request](https://issuetracker.google.com/issues/69250435)
197
+ - DigitalOcean Managed Databases - follow the instructions on [this page](https://docs.digitalocean.com/products/databases/postgresql/details/supported-extensions/#supported-extensions)
198
+
199
+ ## Additional Installation Methods
200
+
201
+ ### Docker
202
+
203
+ Get the [Docker image](https://hub.docker.com/r/ankane/dexter) with:
204
+
205
+ ```sh
206
+ docker pull ankane/dexter
207
+ ```
208
+
209
+ And run it with:
210
+
211
+ ```sh
212
+ docker run -ti ankane/dexter <connection-options>
213
+ ```
214
+
215
+ On Mac and Windows, use `host.docker.internal` as the database hostname for databases on your local machine.
216
+
217
+ ### Homebrew
218
+
219
+ With Homebrew, you can use:
220
+
221
+ ```sh
222
+ brew install ankane/brew/dexter
223
+ ```
194
224
 
195
225
  ## Future Work
196
226
 
@@ -213,7 +243,7 @@ gem specific_install https://github.com/ankane/dexter.git
213
243
 
214
244
  ## Thanks
215
245
 
216
- This software wouldn’t be possible without [HypoPG](https://github.com/dalibo/hypopg), which allows you to create hypothetical indexes, and [pg_query](https://github.com/lfittl/pg_query), which allows you to parse and fingerprint queries. A big thanks to Dalibo and Lukas Fittl respectively.
246
+ This software wouldn’t be possible without [HypoPG](https://github.com/HypoPG/hypopg), which allows you to create hypothetical indexes, and [pg_query](https://github.com/lfittl/pg_query), which allows you to parse and fingerprint queries. A big thanks to Dalibo and Lukas Fittl respectively.
217
247
 
218
248
  ## Research
219
249
 
@@ -240,6 +240,7 @@ module Dexter
240
240
  end
241
241
 
242
242
  def find_columns(plan)
243
+ plan = JSON.parse(plan.to_json)
243
244
  find_by_key(plan, "ColumnRef")
244
245
  end
245
246
 
@@ -248,20 +249,24 @@ module Dexter
248
249
  end
249
250
 
250
251
  def find_by_key(plan, key)
251
- indexes = []
252
- case plan
253
- when Hash
254
- plan.each do |k, v|
255
- if k == key
256
- indexes << v
257
- else
258
- indexes.concat(find_by_key(v, key))
252
+ result = []
253
+ queue = [plan]
254
+ while queue.any?
255
+ node = queue.pop
256
+ case node
257
+ when Hash
258
+ node.each do |k, v|
259
+ if k == key
260
+ result << v
261
+ elsif !v.nil?
262
+ queue << v
263
+ end
259
264
  end
265
+ when Array
266
+ queue.concat(node)
260
267
  end
261
- when Array
262
- indexes.concat(plan.flat_map { |v| find_by_key(v, key) })
263
268
  end
264
- indexes
269
+ result
265
270
  end
266
271
 
267
272
  def hypo_indexes_from_plan(index_name_to_columns, plan, index_set)
@@ -483,10 +488,10 @@ module Dexter
483
488
  statement = String.new("CREATE INDEX CONCURRENTLY ON #{quote_ident(index[:table])} (#{index[:columns].map { |c| quote_ident(c) }.join(", ")})")
484
489
  statement << " TABLESPACE #{quote_ident(@tablespace)}" if @tablespace
485
490
  log "Creating index: #{statement}"
486
- started_at = Time.now
491
+ started_at = monotonic_time
487
492
  begin
488
493
  execute(statement)
489
- log "Index created: #{((Time.now - started_at) * 1000).to_i} ms"
494
+ log "Index created: #{((monotonic_time - started_at) * 1000).to_i} ms"
490
495
  rescue PG::LockNotAvailable
491
496
  log "Could not acquire lock: #{index[:table]}"
492
497
  end
@@ -498,6 +503,10 @@ module Dexter
498
503
  new_indexes
499
504
  end
500
505
 
506
+ def monotonic_time
507
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
508
+ end
509
+
501
510
  def conn
502
511
  @conn ||= begin
503
512
  # set connect timeout if none set
@@ -62,7 +62,7 @@ module Dexter
62
62
  end
63
63
 
64
64
  def process_queries_without_lock
65
- now = Time.now
65
+ now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
66
66
  min_checked_at = now - 3600 # don't recheck for an hour
67
67
  queries = []
68
68
  @collector.fetch_queries.each do |query|
@@ -1,3 +1,3 @@
1
1
  module Dexter
2
- VERSION = "0.3.10"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/dexter.rb CHANGED
@@ -4,6 +4,7 @@ require "pg_query"
4
4
  require "slop"
5
5
 
6
6
  # stdlib
7
+ require "json"
7
8
  require "set"
8
9
  require "time"
9
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgdexter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.10
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-26 00:00:00.000000000 Z
11
+ date: 2022-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: slop
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: pg_query
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "<"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '2'
47
+ version: '2.1'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "<"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '2'
54
+ version: '2.1'
55
55
  description:
56
56
  email: andrew@ankane.org
57
57
  executables:
@@ -87,14 +87,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="
89
89
  - !ruby/object:Gem::Version
90
- version: '2.2'
90
+ version: '2.5'
91
91
  required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: '0'
96
96
  requirements: []
97
- rubygems_version: 3.2.3
97
+ rubygems_version: 3.3.7
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: The automatic indexer for Postgres