(func()).*
dalam Versi PostgreSQL LamaDalam versi PostgreSQL sebelum 9.3, menggunakan sintaks (func()).*
(di mana func
mengembalikan jadual) boleh membawa kepada pelaksanaan berbilang fungsi yang tidak diingini. Ini memberi kesan ketara kepada prestasi pertanyaan.
Beberapa kaedah berkesan memintas masalah ini:
1. Pendekatan Subkueri:
<code class="language-sql">SELECT (mf).* FROM ( SELECT my_func(x) AS mf FROM some_table ) sub;</code>
2. Teknik OFFSET 0:
<code class="language-sql">SELECT (mf).* FROM ( SELECT my_func(x) AS mf FROM some_table OFFSET 0 ) sub;</code>
3. Pendekatan CTE (Ungkapan Jadual Biasa):
<code class="language-sql">WITH tmp(mf) AS ( SELECT my_func(x) FROM some_table ) SELECT (mf).* FROM tmp;</code>
4. SERTAI LATERAL (PostgreSQL 9.3 dan lebih baru):
<code class="language-sql"> SELECT mf.* FROM some_table LEFT JOIN LATERAL my_func(some_table.x) AS mf ON true; ``` This is the preferred method for PostgreSQL 9.3 and above. ### Explanation The root cause lies in how PostgreSQL's parser handles `(func()).*` in older versions. The wildcard expands into individual column selections, mistakenly causing the function to be called repeatedly for each column. ### Why Repeated Calls Occur Pre-9.3 PostgreSQL parsers interpret `(func()).*` by replicating nodes within the parse tree. This replication results in a separate function call for every selected column, even if a single call would suffice.</code>
Atas ialah kandungan terperinci Bagaimana untuk Mencegah Panggilan Berbilang Fungsi dengan `(func()).*` dalam Versi PostgreSQL Lama?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!