![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Is there any way to go around this issue? Like indexing the col2 or giving it a hint on which UNION line to use? |
#3
| |||
| |||
|
|
On Thu, 10 Mar 2011 04:50:11 -0800, NewUser2008 wrote: Is there any way to go around this issue? Like indexing the col2 or giving it a hint on which UNION line to use? Indexing column in a view? Sure, as soon as it is possible to assign rowid to the rows of a view. Not a problem, as long as the view is materialized. I would strongly advise to consider alternative design options. --http://mgogala.byethost5.com |
#4
| |||
| |||
|
#5
| |||
| |||
|
|
Hi, thanks for your reply. Nah, sorry, it's not that easy. I'm trying to find an alternative group management method on database level that is able to manage both explicit group assignment and implicit assignment via an sql statement. For instance (simplified tables here): TABLE IDENTITY: === - id - name TABLE GROUPS === - id - name TABLE EXPLICIT_ASSIGN === - ident_id - group_id VIEW IMPLICIT_ASSIGN -- simplified code... === SELECT ident_id, 512 FROM employeeData WHERE -- several conditions UNION ALL SELECT ident_id, 13012 FROM someOtherTable WHERE -- several conditions UNION ALL SELECT ident_id, 4099 FROM thirdTable WHERE -- several conditions with the purpose of handling those groups seamlessly: VIEW ALL_GROUPS === SELECT * FROM EXPLICIT_ASSIGN UNION ALL SELECT * FROM IMPLICIT_ASSIGN So one only needs to know the group number to get its members. The purpose of not using higher level scripting is that I a) can use this technique on the database level within triggers and stuff and b) feed it SUBQUERIES like SELECT * FROM all_groups WHERE group_id IN (...) Thanks, NewUser2k8 |
#6
| |||
| |||
|
|
A stored function and dynamic SQL is not an option, then I could use my business logic to do the same. Thanks, NewUser2k8 |
#7
| |||
| |||
|
|
Why is it not an option? |
#8
| |||
| |||
|
|
@joel garry: don't think so. It does not involve normalization at this stage; there ist no static modeling involved here. but thanks anyway. @steve howard: Why is it not an option? Here goes. a) create type: CREATE TYPE GROUP_MEMBERSHIP_TYPE IS OBJECT (ident_id NUMBER, group_id NUMBER); b) create result set type: CREATE TYPE GROUP_MEMBERSHIP_SET AS TABLE OF GROUP_MEMBERSHIP_TYPE; c) Write a function: GET_GROUP_MEMBERSHIP(GROUP_ID IN NUMBER) RETURN GROUP_MEMBERSHIP_SET; Now I can select like this: SELECT * FROM TABLE(GET_GROUP_MEMBERSHIP(1512)); which will return the appropriate rows. This solution I implemented with EXECUTE IMMEDIATE dynamic SQL; the SQL works flawlessly. However with the tables from 4th comment: ## SELECT ea.ident_id, ea.group_id, *g.name ## FROM EXPLICIT_ASSIGN ea LEFT ## JOIN GROUPS g ON g.id=ea.group_id ## WHERE g.id IN (SELECT 1,2,3,4,5,6,7 FROM DUAL) -- WORKS! ## SELECT ia.ident_id, ia.group_id, *g.name ## FROM table(GET_GROUP_MEMBERSHIP(???????????)) ia LEFT ## JOIN GROUPS g ON g.id=ia.group_id ## WHERE g.id = IN (SELECT 1,2,3,4,5,6,7 FROM DUAL) -- See? a) how to handle subqueries? b) how to unite with explicit assignment? c) how to reuse in other SQL statements? We'll always have to feed the desired groups into the WHERE clause AND the function parameter, even if the parameter is a table of number as well... With this solution I always have to treat explicit and dynamic group memberships differently on database level. Don't get me wrong: The solution with the view from first post works technically. It's just damn slow with a growing number of UNION ALL statements. But perhaps it's really not solvable on dbms level. |
#9
| |||
| |||
|
|
Maybe, maybe not. It would be interesting and helpful to learn your WHERE conditions for implicit assignments. ok, complete example here. Please use the tables |
|
Btw, another solution might be to encode your implicit assignments into trigger logic and write assignments into the assignment table whenever you insert a new identity. *Advantage: querying will be fast or at least can be tuned more easily, downside is that you need manual intervention whenever your implicit assignments change. *But if that does not happen too often it might be an option nevertheless. Thanks, yes, I had thought of that as well, however, since we use |
#10
| |||
| |||
|
|
Hi, thanks for your reply. Nah, sorry, it's not that easy. I'm trying to find an alternative group management method on database level that is able to manage both explicit group assignment and implicit assignment via an sql statement. For instance (simplified tables here): TABLE IDENTITY: === - id - name TABLE GROUPS === - id - name TABLE EXPLICIT_ASSIGN === - ident_id - group_id VIEW IMPLICIT_ASSIGN -- simplified code... === SELECT ident_id, 512 FROM employeeData WHERE -- several conditions UNION ALL SELECT ident_id, 13012 FROM someOtherTable WHERE -- several conditions UNION ALL SELECT ident_id, 4099 FROM thirdTable WHERE -- several conditions with the purpose of handling those groups seamlessly: VIEW ALL_GROUPS === SELECT * FROM EXPLICIT_ASSIGN UNION ALL SELECT * FROM IMPLICIT_ASSIGN So one only needs to know the group number to get its members. The purpose of not using higher level scripting is that I a) can use this technique on the database level within triggers and stuff and b) feed it SUBQUERIES like SELECT * FROM all_groups WHERE group_id IN (...) Thanks, NewUser2k8 |
![]() |
| Thread Tools | |
| Display Modes | |
| |