Subject | selecting some IDs |
---|---|
Author | Sergio H. Gonzalez |
Post date | 2010-06-04T20:23:53Z |
Hello, I'm trying to figure out what is the way to a very simple task, so I can
use the same method from now on...
I want to let the user select some records in order to make a report.
I have some options:
----------
1) to keep the selected IDs in a string in the client application and then
construct the SQL like this
SELECT * FROM BANCOS WHERE ID in (2,4,7)
Plan
PLAN (BANCOS INDEX (PK_BANCOS, PK_BANCOS, PK_BANCOS))
Adapted Plan
PLAN (BANCOS INDEX (PK_BANCOS, PK_BANCOS, PK_BANCOS))
it seems OK, but I don't know if I have a limit of IDs... can I make a HUGE SQL
string?? Probably this method is not the best is I want to select 10000 records.
Am I wrong?
----------
2) I created a TEMP table (tmp_seleccion) and store the IDs in it:
SELECT * FROM BANCOS WHERE ID in (SELECT ID FROM tmp_seleccion)
The plan doesn't seem to be any good tough...
Plan
PLAN (TMP_SELECCION NATURAL)
PLAN (BANCOS NATURAL)
Adapted Plan
PLAN (TMP_SELECCION NATURAL) PLAN (BANCOS NATURAL)
----------
3) this is the same that 2) I think
SELECT * FROM BANCOS b WHERE exists (SELECT ID FROM tmp_seleccion S where B.id =
S.id)
Plan
PLAN (S NATURAL)
PLAN (B NATURAL)
Adapted Plan
PLAN (S NATURAL) PLAN (B NATURAL)
----------
4) So far, this seems the best:
select B.ID, B.NOMBRE FROM bancos B join tmp_seleccion S ON S.id = B.id
Plan
PLAN JOIN (S NATURAL, B INDEX (PK_BANCOS))
Adapted Plan
PLAN JOIN (S NATURAL, B INDEX (PK_BANCOS))
So should I use 4) ever? Any advice?
THANK YOU VERY MUCH !!
use the same method from now on...
I want to let the user select some records in order to make a report.
I have some options:
----------
1) to keep the selected IDs in a string in the client application and then
construct the SQL like this
SELECT * FROM BANCOS WHERE ID in (2,4,7)
Plan
PLAN (BANCOS INDEX (PK_BANCOS, PK_BANCOS, PK_BANCOS))
Adapted Plan
PLAN (BANCOS INDEX (PK_BANCOS, PK_BANCOS, PK_BANCOS))
it seems OK, but I don't know if I have a limit of IDs... can I make a HUGE SQL
string?? Probably this method is not the best is I want to select 10000 records.
Am I wrong?
----------
2) I created a TEMP table (tmp_seleccion) and store the IDs in it:
SELECT * FROM BANCOS WHERE ID in (SELECT ID FROM tmp_seleccion)
The plan doesn't seem to be any good tough...
Plan
PLAN (TMP_SELECCION NATURAL)
PLAN (BANCOS NATURAL)
Adapted Plan
PLAN (TMP_SELECCION NATURAL) PLAN (BANCOS NATURAL)
----------
3) this is the same that 2) I think
SELECT * FROM BANCOS b WHERE exists (SELECT ID FROM tmp_seleccion S where B.id =
S.id)
Plan
PLAN (S NATURAL)
PLAN (B NATURAL)
Adapted Plan
PLAN (S NATURAL) PLAN (B NATURAL)
----------
4) So far, this seems the best:
select B.ID, B.NOMBRE FROM bancos B join tmp_seleccion S ON S.id = B.id
Plan
PLAN JOIN (S NATURAL, B INDEX (PK_BANCOS))
Adapted Plan
PLAN JOIN (S NATURAL, B INDEX (PK_BANCOS))
So should I use 4) ever? Any advice?
THANK YOU VERY MUCH !!