Subject | RE: [firebird-support] Need help in order to make this sql run efficiently... |
---|---|
Author | ICAMSoft |
Post date | 2005-02-21T00:42:52Z |
First of all,
Pavel, thanks for your reply
[>>]Did you forget WHERE clause here?
"and case_id>0" had to be "where case_id>0"
[>>]Why do you need internal SELECT at all? Try
select * from T_CASES
where case_id>0
and case_id between :minID and :maxID /* your parameters */
Since case_id is PK, there is no need to select distinct values.
In the real program the query is
------------------------------- QUERY ----------------------------
Select * from V_CASES
where V_CASES_GRID.case_id in
(
select distinct(V_CASES.case_ID) from T_cases
where T_CASES.case_id>0
/* ------------here follow the dynamically created criteria */
and T_CASES.case_id between 19 and 30
/* ---------------------------------------- end of criteria */
order by V_CASES.case_id
)
---------------------------------------------------------------------
Where V_CASES is a view which joins T_CASES with enough secondary tables
according the selected criteria fields in the GUI interface.
My thought was to find the needed rows of T_CASES (using the subquery) and
ONLY for them select the revelant rows of V_CASES which has many more fields
(because of joined secondary tables). But - unfortunately - what happens is
that all the T_CASES tables is readed twice :-(
The distinct is used because in some specific criteria can be returned more
than one row (in the view) for each row in the table.
Regards
Tasos Kyriakos
Athens, Greece
tkyr@...
Pavel, thanks for your reply
[>>]Did you forget WHERE clause here?
"and case_id>0" had to be "where case_id>0"
[>>]Why do you need internal SELECT at all? Try
select * from T_CASES
where case_id>0
and case_id between :minID and :maxID /* your parameters */
Since case_id is PK, there is no need to select distinct values.
In the real program the query is
------------------------------- QUERY ----------------------------
Select * from V_CASES
where V_CASES_GRID.case_id in
(
select distinct(V_CASES.case_ID) from T_cases
where T_CASES.case_id>0
/* ------------here follow the dynamically created criteria */
and T_CASES.case_id between 19 and 30
/* ---------------------------------------- end of criteria */
order by V_CASES.case_id
)
---------------------------------------------------------------------
Where V_CASES is a view which joins T_CASES with enough secondary tables
according the selected criteria fields in the GUI interface.
My thought was to find the needed rows of T_CASES (using the subquery) and
ONLY for them select the revelant rows of V_CASES which has many more fields
(because of joined secondary tables). But - unfortunately - what happens is
that all the T_CASES tables is readed twice :-(
The distinct is used because in some specific criteria can be returned more
than one row (in the view) for each row in the table.
Regards
Tasos Kyriakos
Athens, Greece
tkyr@...