![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Table Figure: id | name |
|
Table fig_preferences: id | pref_key | pref_value | fig_ref |
|
Now if I would like to know the names of all figures with color=red and shape=rect it should return fig1 and fig2, but not fig3. ??? |
#3
| |||
| |||
|
|
I have no clue how to design a query for the following scenario in sql: |
#4
| |||
| |||
|
|
Table Figure: id | name -------------- 0 | fig1 1 | fig2 2 | fig3 Table fig_preferences: id | pref_key | pref_value | fig_ref -------------------------------------------------- 0 | color | blue | 0 1 | shape | rect | 0 2 | color | blue | 1 3 | color | red | 2 4 | shape | rect | 2 Now if I would like to know the names of all figures with color=red and shape=rect it should return fig1 and fig2, but not fig3. With other words the query should return all figures that don't have any key-value-pairs in the db that are not in the set of key-value-pairs in the query. Since sql doesn't support any set operations like intersection I have no clue how to proceed. Steffen |
#5
| |||
| |||
|
|
steffen.dienst (AT) gmail (DOT) com> wrote in message news:1163190198.509635.157480 (AT) i42g2000cwa (DOT) googlegroups.com... Table Figure: id | name -------------- 0 | fig1 1 | fig2 2 | fig3 Table fig_preferences: id | pref_key | pref_value | fig_ref -------------------------------------------------- 0 | color | blue | 0 1 | shape | rect | 0 2 | color | blue | 1 3 | color | red | 2 4 | shape | rect | 2 Now if I would like to know the names of all figures with color=red and shape=rect it should return fig1 and fig2, but not fig3. With other words the query should return all figures that don't have any key-value-pairs in the db that are not in the set of key-value-pairs in the query. Since sql doesn't support any set operations like intersection I have no clue how to proceed. Steffen I am not sure I follow. color=red returns line 3. shape=rect returns lines 1,4. Therefore color=red AND shape=rect returns lines 3,4 which when combined point to fig_ref 2 which is fig3. Therefore color=red AND shapre=rect returns fig3. How do you get it to return fig1 and fig2? Am I missing something? The other question I want to ask is, do you have queries such as: color<>red? If you ever need this type of query, you have a huge problem and this will result in full table scans. And what about: color=red OR shape=rect This type of search will also result in full table scans though a lack of definitive index use. If you need to do any of the above, I suggest you look at other methods than what you have above. Are the attributes always consistent and static? If so, I strongly recommend that you make each attribute a column value. Your queries will be much much easier and faster. Make sure your indexing across the values if using a set of concatenated indexes makes best use of filtering your records. I can appreciate why you wish to design the database tables the way you do to allow for dynamic attributes, but if they are not necessary, don't do this. It will cause severe scalability issues. It will also cause performance issues if the user needed to do basic stuff such as see each fig in a table with all its attributes. The cost to build that table can bring your database down if all your users are doing similar things. AMO |
#6
| |||
| |||
|
|
If you need to do any of the above, I suggest you look at other methods than what you have above. Are the attributes always consistent and static? If so, I strongly recommend that you make each attribute a column value. Your queries will be much much easier and faster. Make sure your indexing across the values if using a set of concatenated indexes makes best use of filtering your records. I can appreciate why you wish to design the database tables the way you do to allow for dynamic attributes, but if they are not necessary, don't do this. It will cause severe scalability issues. It will also cause performance issues if the user needed to do basic stuff such as see each fig in a table with all its attributes. The cost to build that table can bring your database down if all your users are doing similar things. AMO |
#7
| |||
| |||
|
|
Good advice AMO. Thanx! |
|
Now do you see why, especially in this group, that we suggest designing tables with real attributes for primary keys? It is just way too easy for the newbies to fall into this autoID trap. Even in our other discussion, I knew you knew this. Ed |

#8
| |||
| |||
|
|
.. there is no reason why he cannot use a sequence or GUID for his primary id. |
|
If his attribute requirement is dynamic, he will require another solution. Now.....what would you suggest if this was the case! ;0) |
#9
| |||
| |||
|
|
.. there is no reason why he cannot use a sequence or GUID for his primary id. Validation? Verification? Portability? |
|
If his attribute requirement is dynamic, he will require another solution. Now.....what would you suggest if this was the case! ;0) More research. --CELKO-- |
#10
| |||
| |||
|
|
There are instances where one needs dynamic attributes... |
|
Alternatively, you can look at solutions which whilst are not conceptually perfect, offer a practical solution. Of course, you can also look at other technologies such as object databases. |
![]() |
| Thread Tools | |
| Display Modes | |
| |