At the moment, we have a system for displaying formatted results. As this is just a "picker" list, which displays a set of "user defined" details about a record, and on clicking that row - the full record details are displayed. The list is meant to be *indicative* of the data contained, not truthful (if you get my meaning)
Unfortunately as this display is user configurable the user can choose something stupid and kinda complicate the whole thing - e.g. the list is a person picker, and they choose to display "skills" as one of the columns. This would mean the person showing in the list more than once (multiply this by other multi occuring columns and .... well you know where thats going.
At the moment, we have a java method that takes this resultset, and works through it ignoring and id's its already seen in the result (basically a "distinct" - but ONLY working on the first column).
// Reset count to 0, and process again for number of rows to return.
currentRow=1;
while ( rsExecuteQuery.next() ){
if (currentRow <= this.getMaxRows())
{
entityID = rsExecuteQuery.getLong(1); //"ENTITY_ID");
if (uniqueEntityIDSet.add(new Long(entityID)))
{
// Wasnt already in the set - so add the row.
row = new ArrayList();
row.add(new Long(entityID));
for (int x = 1; x < colCount; x++)
{
row.add(rsExecuteQuery.getObject(x + 1));
}
resultSet.add(row);
currentRow++;
}
} else {
break;
}
}
It works, but it aint pretty.....
I have been looking for ways to speed this up - trying to offload more of the work to the DB.
I tried recreating it in stored procedures, but didnt get too far with my limited knowlege (further complicated by having to support any database, but I just couldnt get anything working like above).
I have managed to offload the work to the query under SQLServer2005 (and I think I can work it a similar way on Oracle but havent tried yet).
select top 10 * from (
SELECT "ROOT"."ENTITY_ID" AS "ENTITY_ID"
,"LK_ENTITY_ROLE"."DEFAULT_VALUE" AS "DEFAULT_VALUE", "ROOT"."HIGHLIGHT" AS "HIGHLIGHT", "ROOT"."WEIGHTING" AS "WEIGHTING", "ROOT"."AVAILABILITY" AS "AVAILABILITY"
-- ... more columns here.
,row_number() OVER (partition by "ROOT"."ENTITY_ID" ORDER BY "LK_ENTITY_ROLE"."DEFAULT_VALUE" DESC) as filter
FROM "SEARCH_RESULTS" "ROOT"
LEFT OUTER JOIN "LK_ENTITY_ROLE" "LK_ENTITY_ROLE" ON "ROOT"."ENTITY_ID"="LK_ENTITY_ROLE"."ENTITY_ID"
LEFT OUTER JOIN "PROP_SKILLS" "PROP_SKILLS" ON "ROOT"."ENTITY_ID"="PROP_SKILLS"."REFERENCE"
WHERE "ROOT"."SEARCH_ID"=6888502
-- ... more conditions here
)ZZ
where ZZ.filter=1
ORDER BY 2 DESC
It works, but aint all that quick, and wont help me on SqlServer2000 (sigh), so does anyone have any cool ideas?
Im sure this must be a fairly common problem - showing preview data - but im fast approaching breakdown, im just a poor programmer with no database training and a company too tight to get any...
Thanks for listening
<< JOC >>
Unfortunately as this display is user configurable the user can choose something stupid and kinda complicate the whole thing - e.g. the list is a person picker, and they choose to display "skills" as one of the columns. This would mean the person showing in the list more than once (multiply this by other multi occuring columns and .... well you know where thats going.
At the moment, we have a java method that takes this resultset, and works through it ignoring and id's its already seen in the result (basically a "distinct" - but ONLY working on the first column).
// Reset count to 0, and process again for number of rows to return.
currentRow=1;
while ( rsExecuteQuery.next() ){
if (currentRow <= this.getMaxRows())
{
entityID = rsExecuteQuery.getLong(1); //"ENTITY_ID");
if (uniqueEntityIDSet.add(new Long(entityID)))
{
// Wasnt already in the set - so add the row.
row = new ArrayList();
row.add(new Long(entityID));
for (int x = 1; x < colCount; x++)
{
row.add(rsExecuteQuery.getObject(x + 1));
}
resultSet.add(row);
currentRow++;
}
} else {
break;
}
}
It works, but it aint pretty.....
I have been looking for ways to speed this up - trying to offload more of the work to the DB.
I tried recreating it in stored procedures, but didnt get too far with my limited knowlege (further complicated by having to support any database, but I just couldnt get anything working like above).
I have managed to offload the work to the query under SQLServer2005 (and I think I can work it a similar way on Oracle but havent tried yet).
select top 10 * from (
SELECT "ROOT"."ENTITY_ID" AS "ENTITY_ID"
,"LK_ENTITY_ROLE"."DEFAULT_VALUE" AS "DEFAULT_VALUE", "ROOT"."HIGHLIGHT" AS "HIGHLIGHT", "ROOT"."WEIGHTING" AS "WEIGHTING", "ROOT"."AVAILABILITY" AS "AVAILABILITY"
-- ... more columns here.
,row_number() OVER (partition by "ROOT"."ENTITY_ID" ORDER BY "LK_ENTITY_ROLE"."DEFAULT_VALUE" DESC) as filter
FROM "SEARCH_RESULTS" "ROOT"
LEFT OUTER JOIN "LK_ENTITY_ROLE" "LK_ENTITY_ROLE" ON "ROOT"."ENTITY_ID"="LK_ENTITY_ROLE"."ENTITY_ID"
LEFT OUTER JOIN "PROP_SKILLS" "PROP_SKILLS" ON "ROOT"."ENTITY_ID"="PROP_SKILLS"."REFERENCE"
WHERE "ROOT"."SEARCH_ID"=6888502
-- ... more conditions here
)ZZ
where ZZ.filter=1
ORDER BY 2 DESC
It works, but aint all that quick, and wont help me on SqlServer2000 (sigh), so does anyone have any cool ideas?
Im sure this must be a fairly common problem - showing preview data - but im fast approaching breakdown, im just a poor programmer with no database training and a company too tight to get any...
Thanks for listening
<< JOC >>