Skip to content
代码片段 群组 项目
提交 03138714 编辑于 作者: Matt Kasa's avatar Matt Kasa
浏览文件

Add todos config for multiple partition scan detector

上级 1f02f716
No related branches found
No related tags found
无相关合并请求
# frozen_string_literal: true # frozen_string_literal: true
require 'yaml'
class Database class Database
class QueryAnalyzers class QueryAnalyzers
attr_reader :analyzers attr_reader :analyzers
def initialize def initialize
@analyzers = ObjectSpace.each_object(::Class).select { |c| c < Base }.map(&:new) config = YAML.safe_load_file(File.expand_path('query_analyzers.yml', __dir__))
@analyzers = self.class.all.map do |subclass|
subclass_name = subclass.to_s.split('::').last
subclass.new(config[subclass_name])
end
end end
def analyze(query) def analyze(query)
...@@ -15,6 +21,12 @@ def analyze(query) ...@@ -15,6 +21,12 @@ def analyze(query)
def save! def save!
analyzers.each(&:save!) analyzers.each(&:save!)
end end
class << self
def all
ObjectSpace.each_object(::Class).select { |c| c < Base }
end
end
end end
end end
......
MultiplePartitionScanDetector:
tables:
- p_ci_builds
- p_ci_builds_metadata
- p_ci_job_annotations
- p_ci_runner_machine_builds
todos:
# List query fingerprints which should be ignored until they are fixed.
# These fingerprints can be found in the auto_explain pipeline artifacts.
# Example:
# - c2cfe803a497101b
...@@ -7,9 +7,11 @@ class Database ...@@ -7,9 +7,11 @@ class Database
class QueryAnalyzers class QueryAnalyzers
class Base class Base
attr_accessor :output attr_accessor :output
attr_reader :config
def initialize def initialize(config)
@output = {} @output = {}
@config = config
end end
def filename def filename
......
...@@ -5,14 +5,12 @@ ...@@ -5,14 +5,12 @@
class Database class Database
class QueryAnalyzers class QueryAnalyzers
class MultiplePartitionScanDetector < Database::QueryAnalyzers::Base class MultiplePartitionScanDetector < Database::QueryAnalyzers::Base
TABLES = %w[
p_ci_builds p_ci_builds_metadata p_ci_job_annotations p_ci_runner_machine_builds
].freeze
def analyze(query) def analyze(query)
super super
TABLES.each do |table_name| return if config['todos']&.include?(query['fingerprint'])
config['tables'].each do |table_name|
if query['query'].include?(table_name) && query['plan'].to_s.include?('"Subplans Removed"=>0') if query['query'].include?(table_name) && query['plan'].to_s.include?('"Subplans Removed"=>0')
(output[table_name] ||= []) << query (output[table_name] ||= []) << query
end end
...@@ -20,7 +18,7 @@ def analyze(query) ...@@ -20,7 +18,7 @@ def analyze(query)
end end
def save! def save!
TABLES.each do |table_name| config['tables'].each do |table_name|
next unless output[table_name] next unless output[table_name]
Zlib::GzipWriter.open(output_path("#{table_name}_multiple_partition_scans.ndjson")) do |file| Zlib::GzipWriter.open(output_path("#{table_name}_multiple_partition_scans.ndjson")) do |file|
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册