誰もこれに遭遇したことがありますか?Postgres エンタープライズ DB アドバンスト サーバー 11.5.12
sysdate()
(Oracle 独自の) Seq Scan は、この場合、4,782 行の結果になります。
EXPLAIN SELECT p.id, p.practice
FROM PatientStatistics ps
INNER JOIN Patients p
ON p.id=ps.patient
WHERE ps.nextfutureapptdateservertime <= sysdate()
ORDER BY p.id ASC;
Hash Join (cost=799.81..1761.53 rows=4782 width=8)
Hash Cond: (p.id = ps.patient)
-> Index Only Scan using patients_index3 on patients p (cost=0.29..921.44 rows=15442 width=8)
-> Hash (cost=644.11..644.11 rows=4782 width=4)
-> Seq Scan on patientstatistics ps (cost=0.00..644.11 rows=4782 width=4)
Filter: (nextfutureapptdateservertime <= sysdate)
now()
またはcurrent_timestamp
(SQL 標準)に変更すると、問題が修正されます。Postgres は正しく Index を使用しています:
EXPLAIN SELECT p.id, p.practice
FROM PatientStatistics ps
INNER JOIN Patients p
ON p.id=ps.patient
WHERE ps.nextfutureapptdateservertime <= now()
ORDER BY p.id ASC;
Nested Loop (cost=0.57..51.41 rows=17 width=8)
-> Index Only Scan using "patientstatisti_idx$$_0c9a0048" on patientstatistics ps (cost=0.29..8.53 rows=17 width=4)
Index Cond: (nextfutureapptdateservertime <= now())
-> Index Scan using patients_pk on patients p (cost=0.29..2.52 rows=1 width=8)
Index Cond: (id = ps.patient)
これらの関数の出力の違いに注意してください。
SELECT now();
SELECT current_timestamp;
15-JAN-20 09:36:41.932741 -05:00
15-JAN-20 09:36:41.932930 -05:00
SELECT sysdate();
15-JAN-20 09:37:17
おそらく、Postgres の日付インデックスは、10 進数部分を持つ Datetimes を使用してハッシュされます。プランナーは、Decimal を持たない日付が渡されたことを確認し、インデックスのキーが正確に整列しないことを認識しているため、スキャンに戻り、クエリが 100% 正確な結果を提供することを確認します。
30分間のグーグル検索の後、オンラインでこれについて何も見つけることができませんでした.