You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I do not known if this is some issue or as designed
but
if i have query like this
SELECT
A.OBIEKT ,
(SELECT COUNT(*) FROM ELEMENTY_EX EE1 INNER JOIN ELEMENTY_DB E ON E.ID=EE1.ID_ELEM WHERE EE1.ID_OBJ=http://A.ID AND EE1.DATAP1=EE1.DATAP2 AND EE1.CZASP1=EE1.CZASP2 AND E.RODZAJ='Status') AS ILE_STAN1
FROM ADRESY_DB A
without order by i get single plan for subquery (EE1):
PLAN JOIN (EE1 INDEX (IXA__ELEMENTY_EX__ID_OBJ),E INDEX (PK_ELEMENTY_DB__ID))
PLAN (A NATURAL)
but with order by i get 2 plans for subquery (EE1):
SELECT
A.OBIEKT ,
(SELECT COUNT(*) FROM ELEMENTY_EX EE1 INNER JOIN ELEMENTY_DB E ON E.ID=EE1.ID_ELEM WHERE EE1.ID_OBJ=http://A.ID AND EE1.DATAP1=EE1.DATAP2 AND EE1.CZASP1=EE1.CZASP2 AND E.RODZAJ='Status') AS ILE_STAN1
FROM ADRESY_DB A ORDER BY 2 DESC
PLAN JOIN (EE1 INDEX (IXA__ELEMENTY_EX__ID_OBJ),E INDEX (PK_ELEMENTY_DB__ID))
PLAN JOIN (EE1 INDEX (IXA__ELEMENTY_EX__ID_OBJ),E INDEX (PK_ELEMENTY_DB__ID))
PLAN SORT ((A NATURAL))
The text was updated successfully, but these errors were encountered:
This is a known issue, caused by the lack of common sub-expression elimination in Firebird. The sub-query will be executed twice (in the ORDER BY clause and in the select list), hence two plans reported.
In some case this lead to unpredictably results. Example:
CREATE TABLE CALC (
ID INTEGER NOT NULL,
RESULT DOUBLE PRECISION DEFAULT 0
);
COMMIT WORK;
INSERT INTO calc (id, result) VALUES (1, -1);
INSERT INTO calc (id, result) VALUES (2, 2);
INSERT INTO calc (id, result) VALUES (3, -3);
INSERT INTO calc (id, result) VALUES (0, 0);
COMMIT WORK;
SET TERM ^ ;
CREATE OR ALTER PROCEDURE REVERSE_CALC (
ID INTEGER)
RETURNS (
RESULT DOUBLE PRECISION)
AS
BEGIN
SELECT result FROM calc WHERE id = :id INTO :result;
UPDATE calc SET result = - :result WHERE id = :id;
result = COALESCE(result, 0);
SUSPEND;
END
^
SET TERM ; ^
COMMIT WORK;
SELECT (SELECT result FROM reverse_calc(http://c.id)) AS get_result,
c.*
FROM calc c
ORDER BY 1
Submitted by: @livius2
I do not known if this is some issue or as designed
but
if i have query like this
SELECT
A.OBIEKT ,
(SELECT COUNT(*) FROM ELEMENTY_EX EE1 INNER JOIN ELEMENTY_DB E ON E.ID=EE1.ID_ELEM WHERE EE1.ID_OBJ=http://A.ID AND EE1.DATAP1=EE1.DATAP2 AND EE1.CZASP1=EE1.CZASP2 AND E.RODZAJ='Status') AS ILE_STAN1
FROM ADRESY_DB A
without order by i get single plan for subquery (EE1):
PLAN JOIN (EE1 INDEX (IXA__ELEMENTY_EX__ID_OBJ),E INDEX (PK_ELEMENTY_DB__ID))
PLAN (A NATURAL)
but with order by i get 2 plans for subquery (EE1):
SELECT
A.OBIEKT ,
(SELECT COUNT(*) FROM ELEMENTY_EX EE1 INNER JOIN ELEMENTY_DB E ON E.ID=EE1.ID_ELEM WHERE EE1.ID_OBJ=http://A.ID AND EE1.DATAP1=EE1.DATAP2 AND EE1.CZASP1=EE1.CZASP2 AND E.RODZAJ='Status') AS ILE_STAN1
FROM ADRESY_DB A ORDER BY 2 DESC
PLAN JOIN (EE1 INDEX (IXA__ELEMENTY_EX__ID_OBJ),E INDEX (PK_ELEMENTY_DB__ID))
PLAN JOIN (EE1 INDEX (IXA__ELEMENTY_EX__ID_OBJ),E INDEX (PK_ELEMENTY_DB__ID))
PLAN SORT ((A NATURAL))
The text was updated successfully, but these errors were encountered: