ankane/dexter

when auto_explain.log_min_duration=0 ,pgdexter run errors

lirulei opened this issue · 1 comments

software version

# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)

# ruby --version
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]

# gem list | grep dexter
pgdexter (0.5.1)

when i enable auto_explain extension,and setting log_min_duration to 0 , dexter run errors

auto_explain.log_min_duration = '0'
# dexter -d postgres -Udts -h192.168.31.181 --pg-stat-statements --enable-hypopg --log-level debug2
Processing 5 new query fingerprints
Last analyze: public.pgbench_accounts : 2024-01-03T10:49:16+08:00
/opt/rh/rh-ruby30/root/usr/local/share/gems/gems/pgdexter-0.5.1/lib/dexter/indexer.rb:310:in `block in determine_indexes': undefined method `<' for nil:NilClass (NoMethodError)
        from /opt/rh/rh-ruby30/root/usr/local/share/gems/gems/pgdexter-0.5.1/lib/dexter/indexer.rb:306:in `each'
        from /opt/rh/rh-ruby30/root/usr/local/share/gems/gems/pgdexter-0.5.1/lib/dexter/indexer.rb:306:in `determine_indexes'
        from /opt/rh/rh-ruby30/root/usr/local/share/gems/gems/pgdexter-0.5.1/lib/dexter/indexer.rb:102:in `process_queries'
        from /opt/rh/rh-ruby30/root/usr/local/share/gems/gems/pgdexter-0.5.1/lib/dexter/indexer.rb:32:in `process_stat_statements'
        from /opt/rh/rh-ruby30/root/usr/local/share/gems/gems/pgdexter-0.5.1/lib/dexter/client.rb:27:in `perform'
        from /opt/rh/rh-ruby30/root/usr/local/share/gems/gems/pgdexter-0.5.1/lib/dexter/client.rb:9:in `start'
        from /opt/rh/rh-ruby30/root/usr/local/share/gems/gems/pgdexter-0.5.1/exe/dexter:7:in `<top (required)>'
        from /opt/rh/rh-ruby30/root/usr/local/bin/dexter:23:in `load'
        from /opt/rh/rh-ruby30/root/usr/local/bin/dexter:23:in `<main>'

I add some logs:

      queries.each do |query|
        if query.explainable? && query.high_cost?
          puts "query.costs -->", query.costs       # add this line
          puts "query.costs.length -->", query.costs.length  # add this line
          new_cost, new_cost2 = query.costs[1..2]

then rerun dexter with different auto_explain.log_min_duration value:

when auto_explain.log_min_duration is not zero:
query.costs -->
172875.43
query.costs.length --> 
1
new_cost -->

new_cost2 -->


when auto_explain.log_min_duration = '0':
query.costs -->
172875.43
8.07
8.07
query.costs.length -->
3
new_cost -->
8.07
new_cost2 -->
8.07

I think An exception occurred while retrieving query.costs value

Hi @lirulei, thanks for reporting! It looks like auto_explain and HypoPG may not be compatible, as this error occurs when trying to explain a query:

ERROR:  cache lookup failed for index 13017

I've pushed a fix in the commit above so Dexter won't error in this situation.