Quote:
Quote:
>I have a large Parents [referenced?] table, with an even larger child [referencing?] table (approx 5 rows per Parents [referenced?] item). <<
You are using terminology FROM network databases AND NOT RDBMS. A
table with a singular name will have only one row it in; if it were a
SET, THEN there would be a plural OR collective name. This is very
basic data modeling, so what you have makes it hard to understand
Quote:
Quote:
>I want to join Parents [sic] data with only one row (the most current) from child [sic] table. The overall predicate for the join is highly selective, but is very verbose and involves lots of tables. I tried materializing the child's [sic] data several ways, but always end up with a big table scan. <<
Let me try to clean up your personal pseudo-code and amek guesses
about DRI:
CREATE TABLE Parents
(parent_id INTEGER NOT NULL PRIMARY KEY,
some_info VARCHAR (100) NOT NULL);
CREATE TABLE Children
(parent_id INTEGER NOT NULL
REFERENCES Parents (parent_id)
ON UPDATE CASCADE
ON DELETE CASCADE,
event_time TIMESTAMP NOT NULL,
PRIMARY KEY (parent_id, event_time),
other_info VARCHAR(100) NOT NULL);
Did I guess right? Here is another guess, using the MAX() OVER()
option to get the desired child for each parent. Untested, of course.
SELECT X.parent_id, X.some_info, X.event_time, X.other_info
FROM (SELECT P.parent_id, P.some_info, C.event_time, C.other_info,
MAX(C.event_time)
OVER (PARTITION BY P.parent_id) AS event_time_max
FROM Parents AS P,
Children AS C,
<a bunch of other tables>
WHERE C.parent_id = P.parent_id
AND <some search conditions on other tables>)
AS X
WHERE X.event_time = X.event_time_max;