So, I've been provided with a database structure and the corresponding data from an upstream provider, which looks kinda like:
what I need in order to build and link into the parent data structure:
parent_index, child_seq_id, child_seq_name, child_sequence_num, child_index, child_value1, child_value2
I started out with a single join to get the parent and child relations:
which runs fairly fast.
Then, to add the sequence name to the result, I add the second join:
But this never seems to finish (I usually wait up to 15m to make sure.) I'm guessing I'm accidentally causing a cross join somehow?
I'm correct in my thinking that I should never have more than SELECT COUNT(1) FROM CHILD_SEQUENCE rows in my final query results, yes?
Code:
PARENT
------------------
PARENT_INDEX
.
. 411 other fields...
.
CHILD_SEQUENCE -- 192991 rows
------------------
PARENT_INDEX
CHILD_SEQUENCE_NUM -- Gives the order to the values of the sequence
CHILD_INDEX
CHILD_SEQ_ID
CHILD_SEQUENCE_NAME -- this just gives an optional name to the sequence
-------------------
PARENT_INDEX
CHILD_SEQ_ID
CHILD_SEQ_NAME
CHILD_VALUES -- 171368 rows
----------------
PARENT_INDEX
CHILD_INDEX
CHILD_VALUE1
CHILD_VALUE2
what I need in order to build and link into the parent data structure:
parent_index, child_seq_id, child_seq_name, child_sequence_num, child_index, child_value1, child_value2
I started out with a single join to get the parent and child relations:
Code:
select
cs.parent_index, cs.child_sequence_num, cs.child_index, cs.child_seq_id,
c.child_index, c.child_value1, c.child_value2
from
child_sequence cs
join child_values c
on cs.parent_index = c.parent_index and
cs.child_index = c.child_index
which runs fairly fast.
Then, to add the sequence name to the result, I add the second join:
Code:
select
cs.parent_index, cs.child_sequence_num, cs.child_index, cs.child_seq_id,
csn.child_seq_name,
c.child_index, c.child_value1, c.child_value2
from
child_sequence cs
join child_values c
on cs.parent_index = c.parent_index and
cs.child_index = c.child_index
join child_sequence_name csn
on cs.parent_index = csn.parent_index and
cs.child_seq_id = csn.child_seq_id
But this never seems to finish (I usually wait up to 15m to make sure.) I'm guessing I'm accidentally causing a cross join somehow?
I'm correct in my thinking that I should never have more than SELECT COUNT(1) FROM CHILD_SEQUENCE rows in my final query results, yes?