New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update query hang totally on FB3 (infinite loop) [CORE5748] #6011
Comments
Modified by: @livius2Attachment: testCOREHang.7z [ 13209 ] |
Commented by: @sim1984 Try rewriting this query using the MERGE statement |
Commented by: @livius2 I can rewrite it from "in" into "Exists" statment simply but engine should not go into infinite loop and about this is this report |
Commented by: @AlexPeshkoff Karol, that's known issue. Since FB2.0 (or 2.1 - does not matter too much) IN is executed exactly according to SQL specification but this causes inability to use index. And what you see as an infinite loop is actually 2 recursive IN statements with full scans. |
Commented by: @dyemanov Alex, you're correct about NOT IN, but IN is able to use indices. Not in this example though, because concatenation is used. The slow execution reason is elsewhere, especially given that plans are the same. |
Commented by: @livius2 I have attached stats after 30 minutes |
Modified by: @livius2Attachment: FBHangQuery.png [ 13210 ] |
Commented by: Sean Leyne (seanleyne) Replaced SQL with more readable version |
Modified by: Sean Leyne (seanleyne)description: We try to migrate database from Interbase to Firebird but query hang on FB - with same query plan restore attached database backup qyery run without any problem on Interbase but hang totally on FB3 -------------------------------------------- update sprawozdanie s1 set s1.spr_zlec_fakt_rok = 2018, s1.spr_zlec_fakt_nr = 216 -------------------- plan: legacy ---------------------------- Select Expression ---------------- => We try to migrate database from Interbase to Firebird but query hang on FB - with same query plan restore attached database backup qyery run without any problem on Interbase but hang totally on FB3 -------------------------------------------- update SPRAWOZDANIE S1 -------------------- plan: legacy ---------------------------- Select Expression ---------------- |
Commented by: Sean Leyne (seanleyne) Karol, This issue seems more of an optimization question then a new engine issue (there is already a tracker case about the optimization of IN() operand), as such I believe this case should be closed as duplicate. |
Commented by: @livius2 @sean Leyne i do not suppose that this is only optimization problem. also table OKRES: 6k rows |
Commented by: @livius2 @sean Leyne Executing statement... |
Submitted by: @livius2
Is duplicated by CORE1769
Attachments:
testCOREHang.7z
FBHangQuery.png
We try to migrate database from Interbase to Firebird but query hang on FB - with same query plan
restore attached database backup
there are two tables
SPRAWOZDANIE: 97k rows
OKRES: 6k rows
qyery run without any problem on Interbase but hang totally on FB3
i kill it after 30 minutes. It looks like infinite loop reached. There is "in" operator involved.
--------------------------------------------
update SPRAWOZDANIE S1
set S1.SPR_ZLEC_FAKT_ROK = 2018,
S1.SPR_ZLEC_FAKT_NR = 216
where
S1.DYR_ID = 14 and
S1.DYR_ID || '_' || S1.SPR_ID in (
select S.DYR_ID || '_' || S.SPR_ID
from SPRAWOZDANIE S
where
S.DYR_ID = 14 and
S.UMOWA_ID = '04130038' and
case S.UMOWA_ZLECFAKT_OKRES_ID
when 1 then S.SPR_OKRES_OD || '-' || coalesce(S.SPR_OKRES_DO, S.SPR_OKRES_OD)
when 2 then S.SPR_OKRES_OD || '-' || S.SPR_OKRES_OD /*podzapytanie: wybieramy nr kwartalu dla zadanego okres_numer zapytanie glowne: poczatkowy i koncowy okres_numer dla znalezionego okres_kwartal*/
when 3 then (
select min(O1.OKRES_NUMER) || '-' || max(O1.OKRES_NUMER)
from OKRES O1
where O1.DYR_ID || O1.OKRES_KWARTAL in (
select O2.DYR_ID || O2.OKRES_KWARTAL
from OKRES O2
where
O2.OKRES_NUMER = S.SPR_OKRES_OD and
O2.DYR_ID = S.DYR_ID
)
)
when 4 then (
select min(O1.OKRES_NUMER) || '-' || max(O1.OKRES_NUMER)
from OKRES O1
where O1.DYR_ID || O1.OKRES_POLROCZE in (
select O2.DYR_ID || O2.OKRES_POLROCZE
from OKRES O2
where
O2.OKRES_NUMER = S.SPR_OKRES_OD and
O2.DYR_ID = S.DYR_ID
)
)
when 5 then (
select min(O1.OKRES_NUMER) || '-' || max(O1.OKRES_NUMER)
from OKRES O1
where
O1.DYR_ID || O1.OKRES_ROK in (
select O2.DYR_ID || O2.OKRES_ROK
from OKRES O2
where
O2.OKRES_NUMER = S.SPR_OKRES_OD and
O2.DYR_ID = S.DYR_ID
)
)
else 'bledna wartosc s.umowa_zlecfakt_okres_id'
end = '2018.01-2018.03' and
S.STATUS_ID = 1 and
S.STATUS_ID <> 2
) and
S1.SPR_ZLEC_FAKT_NR is null
--------------------
plan: legacy
PLAN (O2 INDEX (OKRES_PK))
PLAN (O1 NATURAL)
PLAN (O2 INDEX (OKRES_PK))
PLAN (O1 NATURAL)
PLAN (O2 INDEX (OKRES_PK))
PLAN (O1 NATURAL)
PLAN (S INDEX (IXA_SPRAWOZDANIE__UMOWA))
PLAN (S1 INDEX (IXA_SPRAWOZDANIE__DYREKCJA))
----------------------------
plan explained
Select Expression
-> Filter
-> Filter
-> Table "OKRES" as "O2" Access By ID
-> Bitmap
-> Index "OKRES_PK" Unique Scan
Select Expression
-> Singularity Check
-> Aggregate
-> Filter
-> Table "OKRES" as "O1" Full Scan
Select Expression
-> Filter
-> Filter
-> Table "OKRES" as "O2" Access By ID
-> Bitmap
-> Index "OKRES_PK" Unique Scan
Select Expression
-> Singularity Check
-> Aggregate
-> Filter
-> Table "OKRES" as "O1" Full Scan
Select Expression
-> Filter
-> Filter
-> Table "OKRES" as "O2" Access By ID
-> Bitmap
-> Index "OKRES_PK" Unique Scan
Select Expression
-> Singularity Check
-> Aggregate
-> Filter
-> Table "OKRES" as "O1" Full Scan
Select Expression
-> Filter
-> Filter
-> Table "SPRAWOZDANIE" as "S" Access By ID
-> Bitmap
-> Index "IXA_SPRAWOZDANIE__UMOWA" Range Scan (partial match: 2/3)
Select Expression
-> Filter
-> Table "SPRAWOZDANIE" as "S1" Access By ID
-> Bitmap
-> Index "IXA_SPRAWOZDANIE__DYREKCJA" Range Scan (full match)
----------------
tested under
WI-V3.0.3.32897 Firebird 3.0
and also current snapshot
WI-V3.0.4.32912 Firebird 3.0
The text was updated successfully, but these errors were encountered: