pgdexter 0.5.2 → 0.5.3

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: e51edc18f4049b9ca811e4662248aa7a23e748b000975a87fa4a431f49ec632b
4
- data.tar.gz: f3aa243431e0aab1d84d4cbc48ee6a329581acedc7a9c70e2a13e7bb0e15b529
3
+ metadata.gz: d40fb941685400a6a158502895da0d8b93d94db03da0ca4551714aea36e3dae3
4
+ data.tar.gz: 8b99de845f8d6f2e455e98c3505e689a0a55dac69f7c08ba6ebebabeeb1ddd63
5
5
  SHA512:
6
- metadata.gz: 67b04a3c336c3bec239490a386825153699c646a01f5fe30d84b42445695f2431b1545bace72c5b955e03e92ad531810b5a73971d559abb06f175a1965454b89
7
- data.tar.gz: 63691b01566b54056201c2d0a5c73a8153252b7c2ce4619983feb3b20e58d49d4a738b210be61d46231d3b5c78c1787664c625c0eb0216ee0d9ba19dcc8a7621
6
+ metadata.gz: b2b25419796e276074f5a49b2d109be72789ddf8a5c7c5cf29ba55900ac79c323e55b06bf5ab20dde4d34e4cf1e752e7362d23481d21d19a8b068a360562d13f
7
+ data.tar.gz: 382792e95461d718489d36c71e1ba01940f4b1d76de1b80527f0a4a19fcc90c215366645640970271011d5ad2c264051be57e62684e3278248d52bfaae983cd2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.5.3 (2024-03-05)
2
+
3
+ - Fixed error with hypothetical index limit
4
+ - Fixed error with foreign tables
5
+
1
6
  ## 0.5.2 (2024-01-10)
2
7
 
3
8
  - Added Docker image for `linux/arm64`
@@ -96,10 +96,16 @@ module Dexter
96
96
  analyze_tables(tables) if tables.any? && (@analyze || @log_level == "debug2")
97
97
 
98
98
  # create hypothetical indexes and explain queries
99
- candidates = tables.any? ? create_hypothetical_indexes(queries.select(&:candidate_tables)) : {}
99
+ if tables.any?
100
+ # process in batches to prevent "hypopg: not more oid available" error
101
+ # https://hypopg.readthedocs.io/en/rel1_stable/usage.html#configuration
102
+ queries.select(&:candidate_tables).each_slice(500) do |batch|
103
+ create_hypothetical_indexes(batch)
104
+ end
105
+ end
100
106
 
101
107
  # see if new indexes were used and meet bar
102
- new_indexes = determine_indexes(queries, candidates, tables)
108
+ new_indexes = determine_indexes(queries, tables)
103
109
 
104
110
  # display and create new indexes
105
111
  show_and_create_indexes(new_indexes, queries)
@@ -228,7 +234,9 @@ module Dexter
228
234
  calculate_plan(explainable_queries)
229
235
  end
230
236
 
231
- candidates
237
+ queries.each do |query|
238
+ query.candidates = candidates
239
+ end
232
240
  end
233
241
 
234
242
  def find_columns(plan)
@@ -282,9 +290,8 @@ module Dexter
282
290
  query_indexes
283
291
  end
284
292
 
285
- def determine_indexes(queries, candidates, tables)
293
+ def determine_indexes(queries, tables)
286
294
  new_indexes = {}
287
- index_name_to_columns = candidates.invert
288
295
 
289
296
  # filter out existing indexes
290
297
  # this must happen at end of process
@@ -313,11 +320,11 @@ module Dexter
313
320
  cost_savings2 = new_cost > 100 && new_cost2 < new_cost * savings_ratio
314
321
 
315
322
  key = cost_savings2 ? 2 : 1
316
- query_indexes = hypo_indexes_from_plan(index_name_to_columns, query.plans[key], index_set)
323
+ query_indexes = hypo_indexes_from_plan(query.candidates, query.plans[key], index_set)
317
324
 
318
325
  # likely a bad suggestion, so try single column
319
326
  if cost_savings2 && query_indexes.size > 1
320
- query_indexes = hypo_indexes_from_plan(index_name_to_columns, query.plans[1], index_set)
327
+ query_indexes = hypo_indexes_from_plan(query.candidates, query.plans[1], index_set)
321
328
  cost_savings2 = false
322
329
  end
323
330
 
@@ -390,8 +397,8 @@ module Dexter
390
397
 
391
398
  # TODO optimize
392
399
  if @log_level.start_with?("debug")
393
- query.pass1_indexes = hypo_indexes_from_plan(index_name_to_columns, query.plans[1], index_set)
394
- query.pass2_indexes = hypo_indexes_from_plan(index_name_to_columns, query.plans[2], index_set)
400
+ query.pass1_indexes = hypo_indexes_from_plan(query.candidates, query.plans[1], index_set)
401
+ query.pass2_indexes = hypo_indexes_from_plan(query.candidates, query.plans[2], index_set)
395
402
  end
396
403
  end
397
404
  end
@@ -595,7 +602,8 @@ module Dexter
595
602
  columns_by_table.each do |table, cols|
596
603
  # no reason to use btree index for json columns
597
604
  cols.reject { |c| ["json", "jsonb"].include?(c[:type]) }.permutation(n) do |col_set|
598
- candidates[col_set] = create_hypothetical_index(table, col_set)
605
+ index_name = create_hypothetical_index(table, col_set)
606
+ candidates[index_name] = col_set
599
607
  end
600
608
  end
601
609
  end
@@ -612,6 +620,7 @@ module Dexter
612
620
  information_schema.tables
613
621
  WHERE
614
622
  table_catalog = current_database()
623
+ AND table_type IN ('BASE TABLE', 'VIEW')
615
624
  SQL
616
625
  result.map { |r| r["table_name"] }
617
626
  end
data/lib/dexter/query.rb CHANGED
@@ -2,7 +2,7 @@ module Dexter
2
2
  class Query
3
3
  attr_reader :statement, :fingerprint, :plans
4
4
  attr_writer :tables
5
- attr_accessor :missing_tables, :new_cost, :total_time, :calls, :indexes, :suggest_index, :pass1_indexes, :pass2_indexes, :pass3_indexes, :candidate_tables, :tables_from_views
5
+ attr_accessor :missing_tables, :new_cost, :total_time, :calls, :indexes, :suggest_index, :pass1_indexes, :pass2_indexes, :pass3_indexes, :candidate_tables, :tables_from_views, :candidates
6
6
 
7
7
  def initialize(statement, fingerprint = nil)
8
8
  @statement = statement
@@ -1,3 +1,3 @@
1
1
  module Dexter
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
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.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-10 00:00:00.000000000 Z
11
+ date: 2024-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: csv