ऑप्टिमाइज़ करें मेरे पास पोस्टग्रेएसक्यूएल 9.1 में 2 टेबल हैं - flight_2012_09_12 जिसमें लगभग 500,000 पंक्तियां और स्थिति_2012_09_12 हैं जिनमें लगभग 5.5 मिलियन पंक्तियां हैं। मैं एक साधारण जॉइन क्वेरी चला रहा हूं और इसे पूरा करने में काफी समय लग रहा है और इस तथ्य के बावजूद कि टेबल छोटे नहीं हैं, मुझे विश्वास है कि निष्पादन में कुछ प्रमुख लाभ किए जा सकते हैं।पोस्टग्रेस्क्ल क्वेरी
क्वेरी है:
SELECT f.departure, f.arrival,
p.callsign, p.flightkey, p.time, p.lat, p.lon, p.altitude_ft, p.speed
FROM position_2012_09_12 AS p
JOIN flight_2012_09_12 AS f
ON p.flightkey = f.flightkey
WHERE p.lon < 0
AND p.time BETWEEN '2012-9-12 0:0:0' AND '2012-9-12 23:0:0'
समझाने का विश्लेषण के उत्पादन में है:
Hash Join (cost=239891.03..470396.82 rows=4790498 width=51) (actual time=29203.830..45777.193 rows=4403717 loops=1)
Hash Cond: (f.flightkey = p.flightkey)
-> Seq Scan on flight_2012_09_12 f (cost=0.00..1934.31 rows=70631 width=12) (actual time=0.014..220.494 rows=70631 loops=1)
-> Hash (cost=158415.97..158415.97 rows=3916885 width=43) (actual time=29201.012..29201.012 rows=3950815 loops=1)
Buckets: 2048 Batches: 512 (originally 256) Memory Usage: 1025kB
-> Seq Scan on position_2012_09_12 p (cost=0.00..158415.97 rows=3916885 width=43) (actual time=0.006..14630.058 rows=3950815 loops=1)
Filter: ((lon < 0::double precision) AND ("time" >= '2012-09-12 00:00:00'::timestamp without time zone) AND ("time" <= '2012-09-12 23:00:00'::timestamp without time zone))
Total runtime: 58522.767 ms
मुझे लगता है कि समस्या स्थिति मेज पर अनुक्रमिक स्कैन के साथ निहित है, लेकिन मैं बाहर क्यों समझ नहीं सकता यह वहाँ है। सूचकांक तालिका संरचनाओं में नीचे हैं:
Table "public.flight_2012_09_12"
Column | Type | Modifiers
--------------------+-----------------------------+-----------
callsign | character varying(8) |
flightkey | integer |
source | character varying(16) |
departure | character varying(4) |
arrival | character varying(4) |
original_etd | timestamp without time zone |
original_eta | timestamp without time zone |
enroute | boolean |
etd | timestamp without time zone |
eta | timestamp without time zone |
equipment | character varying(6) |
diverted | timestamp without time zone |
time | timestamp without time zone |
lat | double precision |
lon | double precision |
altitude | character varying(7) |
altitude_ft | integer |
speed | character varying(4) |
asdi_acid | character varying(4) |
enroute_eta | timestamp without time zone |
enroute_eta_source | character varying(1) |
Indexes:
"flight_2012_09_12_flightkey_idx" btree (flightkey)
"idx_2012_09_12_altitude_ft" btree (altitude_ft)
"idx_2012_09_12_arrival" btree (arrival)
"idx_2012_09_12_callsign" btree (callsign)
"idx_2012_09_12_departure" btree (departure)
"idx_2012_09_12_diverted" btree (diverted)
"idx_2012_09_12_enroute_eta" btree (enroute_eta)
"idx_2012_09_12_equipment" btree (equipment)
"idx_2012_09_12_etd" btree (etd)
"idx_2012_09_12_lat" btree (lat)
"idx_2012_09_12_lon" btree (lon)
"idx_2012_09_12_original_eta" btree (original_eta)
"idx_2012_09_12_original_etd" btree (original_etd)
"idx_2012_09_12_speed" btree (speed)
"idx_2012_09_12_time" btree ("time")
Table "public.position_2012_09_12"
Column | Type | Modifiers
-------------+-----------------------------+-----------
callsign | character varying(8) |
flightkey | integer |
time | timestamp without time zone |
lat | double precision |
lon | double precision |
altitude | character varying(7) |
altitude_ft | integer |
course | integer |
speed | character varying(4) |
trackerkey | integer |
the_geom | geometry |
Indexes:
"index_2012_09_12_altitude_ft" btree (altitude_ft)
"index_2012_09_12_callsign" btree (callsign)
"index_2012_09_12_course" btree (course)
"index_2012_09_12_flightkey" btree (flightkey)
"index_2012_09_12_speed" btree (speed)
"index_2012_09_12_time" btree ("time")
"position_2012_09_12_flightkey_idx" btree (flightkey)
"test_index" btree (lon)
"test_index_lat" btree (lat)
मैं किसी अन्य तरीके से क्वेरी के पुनर्लेखन के लिए और इसलिए मैं इस बिंदु पर स्टम्प्ड रहा हूँ के बारे में सोच नहीं कर सकते। यदि वर्तमान सेटअप उतना अच्छा है जितना ऐसा हो जाता है लेकिन ऐसा लगता है कि यह वर्तमान में उससे कहीं अधिक तेज़ होना चाहिए। कोई भी सहायताकाफी प्रशंसनीय होगी।
क्या आप public.position_2012_09_12 टेबल लॉन और समय कॉलम पर आंकड़े प्रदान कर सकते हैं? हो सकता है कि कुछ (समय) जहां लोन <0 इंडेक्स मदद करेगा लेकिन स्थिति तालिका में 3950815 पंक्तियां हैं जो इस परिस्थितियों से मेल खाते हैं। क्या इस टेबल में बहुत अधिक डेटा है? – sufleR
उस तालिका में 5563070 पंक्तियां हैं (मेरी पोस्ट को संपादित करने के लिए संपादित किया गया है कि मूल रूप से 3.5 मिलियन के बारे में बताया गया है) – TheOx
पोस्टग्रेस्क्ल का कौन सा संस्करण आप उपयोग कर रहे हैं? – plang