2021-04-08 11:09:06 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Database
|
2021-11-24 10:14:19 -05:00
|
|
|
class PgClass < SharedModel
|
2021-04-08 11:09:06 -04:00
|
|
|
self.table_name = 'pg_class'
|
|
|
|
|
|
|
|
def self.for_table(relname)
|
|
|
|
joins("LEFT JOIN pg_stat_user_tables ON pg_stat_user_tables.relid = pg_class.oid")
|
|
|
|
.where('schemaname = current_schema()')
|
|
|
|
.find_by(relname: relname)
|
|
|
|
end
|
|
|
|
|
|
|
|
def cardinality_estimate
|
|
|
|
tuples = reltuples.to_i
|
|
|
|
|
|
|
|
return if tuples < 1
|
|
|
|
|
|
|
|
tuples
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|