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 +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/dexter/indexer.rb +19 -10
- data/lib/dexter/query.rb +1 -1
- data/lib/dexter/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: d40fb941685400a6a158502895da0d8b93d94db03da0ca4551714aea36e3dae3
|
4
|
+
data.tar.gz: 8b99de845f8d6f2e455e98c3505e689a0a55dac69f7c08ba6ebebabeeb1ddd63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2b25419796e276074f5a49b2d109be72789ddf8a5c7c5cf29ba55900ac79c323e55b06bf5ab20dde4d34e4cf1e752e7362d23481d21d19a8b068a360562d13f
|
7
|
+
data.tar.gz: 382792e95461d718489d36c71e1ba01940f4b1d76de1b80527f0a4a19fcc90c215366645640970271011d5ad2c264051be57e62684e3278248d52bfaae983cd2
|
data/CHANGELOG.md
CHANGED
data/lib/dexter/indexer.rb
CHANGED
@@ -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
|
-
|
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,
|
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
|
-
|
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,
|
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(
|
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(
|
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(
|
394
|
-
query.pass2_indexes = hypo_indexes_from_plan(
|
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
|
-
|
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
|
data/lib/dexter/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2024-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: csv
|