尽管查询速度很快,但显示大量行仍然很慢

时间:2016-02-25 11:36:18

标签: sql postgresql

我遇到一个问题需要花费太长时间(约5秒)。我已经阅读了很多pg表演帖子,但他们让我感到困惑。希望你能帮助我!

EXPLAIN ANALYZE
  SELECT e.uid AS employee_uid, loc.city, eco.company_name as company, et.tag, el.name as language, eq.qualification_type as qualification
  FROM employee e
  LEFT JOIN employee_tag et ON et.employee_uid = e.uid
  LEFT JOIN employee_qualification eq ON eq.employee_uid = e.uid
  LEFT JOIN employee_address ea ON ea.employee_uid = e.uid
  LEFT JOIN address a ON ea.address = a.id
  LEFT JOIN location loc ON loc.id = a.location
  LEFT JOIN employee_spoken_language el ON el.employee_uid = e.uid
  LEFT JOIN employee_company eco ON eco.employee_uid = e.uid
  WHERE 
    e.is_activated = True
    AND e.is_expired = False
    AND eco.company_name IN ('mycompany')
    AND (e.uid IN ('_null') OR True = True)
"Hash Right Join  (cost=175.88..368.89 rows=7267 width=105) (actual time=4.563..18.427 rows=47902 loops=1)"
"  Hash Cond: ((et.employee_uid)::text = (e.uid)::text)"
"  ->  Seq Scan on employee_tag et  (cost=0.00..94.49 rows=4149 width=71) (actual time=0.004..0.466 rows=4149 loops=1)"
"  ->  Hash  (cost=167.60..167.60 rows=663 width=91) (actual time=4.547..4.547 rows=2737 loops=1)"
"        Buckets: 1024  Batches: 1  Memory Usage: 321kB"
"        ->  Hash Right Join  (cost=137.72..167.60 rows=663 width=91) (actual time=2.366..3.359 rows=2737 loops=1)"
"              Hash Cond: ((eq.employee_uid)::text = (e.uid)::text)"
"              ->  Seq Scan on employee_qualification eq  (cost=0.00..20.17 rows=817 width=64) (actual time=0.004..0.098 rows=817 loops=1)"
"              ->  Hash  (cost=133.87..133.87 rows=308 width=82) (actual time=2.354..2.354 rows=821 loops=1)"
"                    Buckets: 1024  Batches: 1  Memory Usage: 89kB"
"                    ->  Hash Right Join  (cost=109.86..133.87 rows=308 width=82) (actual time=1.534..1.992 rows=821 loops=1)"
"                          Hash Cond: ((el.employee_uid)::text = (e.uid)::text)"
"                          ->  Seq Scan on employee_spoken_language el  (cost=0.00..17.95 rows=795 width=64) (actual time=0.003..0.078 rows=795 loops=1)"
"                          ->  Hash  (cost=108.03..108.03 rows=147 width=75) (actual time=1.519..1.519 rows=283 loops=1)"
"                                Buckets: 1024  Batches: 1  Memory Usage: 29kB"
"                                ->  Hash Right Join  (cost=79.89..108.03 rows=147 width=75) (actual time=1.093..1.394 rows=283 loops=1)"
"                                      Hash Cond: (loc.id = a.location)"
"                                      ->  Seq Scan on location loc  (cost=0.00..22.11 rows=911 width=17) (actual time=0.003..0.105 rows=911 loops=1)"
"                                      ->  Hash  (cost=78.05..78.05 rows=147 width=74) (actual time=1.073..1.073 rows=283 loops=1)"
"                                            Buckets: 1024  Batches: 1  Memory Usage: 30kB"
"                                            ->  Hash Right Join  (cost=67.53..78.05 rows=147 width=74) (actual time=0.695..0.863 rows=283 loops=1)"
"                                                  Hash Cond: (a.id = ea.address)"
"                                                  ->  Seq Scan on address a  (cost=0.00..7.40 rows=440 width=16) (actual time=0.004..0.042 rows=440 loops=1)"
"                                                  ->  Hash  (cost=65.69..65.69 rows=147 width=74) (actual time=0.684..0.684 rows=283 loops=1)"
"                                                        Buckets: 1024  Batches: 1  Memory Usage: 30kB"
"                                                        ->  Hash Right Join  (cost=52.41..65.69 rows=147 width=74) (actual time=0.415..0.612 rows=283 loops=1)"
"                                                              Hash Cond: ((ea.employee_uid)::text = (e.uid)::text)"
"                                                              ->  Seq Scan on employee_address ea  (cost=0.00..10.23 rows=423 width=64) (actual time=0.004..0.041 rows=423 loops=1)"
"                                                              ->  Hash  (cost=50.76..50.76 rows=132 width=66) (actual time=0.398..0.398 rows=181 loops=1)"
"                                                                    Buckets: 1024  Batches: 1  Memory Usage: 17kB"
"                                                                    ->  Hash Join  (cost=8.85..50.76 rows=132 width=66) (actual time=0.138..0.327 rows=181 loops=1)"
"                                                                          Hash Cond: ((e.uid)::text = (eco.employee_uid)::text)"
"                                                                          ->  Seq Scan on employee e  (cost=0.00..39.79 rows=213 width=61) (actual time=0.016..0.124 rows=195 loops=1)"
"                                                                                Filter: (is_activated AND (NOT is_expired))"
"                                                                                Rows Removed by Filter: 184"
"                                                                          ->  Hash  (cost=5.93..5.93 rows=234 width=62) (actual time=0.112..0.112 rows=234 loops=1)"
"                                                                                Buckets: 1024  Batches: 1  Memory Usage: 22kB"
"                                                                                ->  Seq Scan on employee_company eco  (cost=0.00..5.93 rows=234 width=62) (actual time=0.007..0.054 rows=234 loops=1)"
"                                                                                      Filter: ((company_name)::text = 'mycompany'::text)"
"Planning time: 4.376 ms"
"Execution time: 19.929 ms"

以下是解释结果:Explain Result

0 个答案:

没有答案