![]() | |
#1
| |||
| |||
|
#2
| |||||
| |||||
|
|
Hello, currently, we are using strings like "pending" or "finished" in some tables to specify the state of certain jobs stored in these tables. These values are self-explaining. These columns are indexed, of course. But I guess, lookups of jobs with certain states would be much faster, if the states would be stored is integer values, e.g. pending = 1, finished = 2 and so on. |
|
However, these values wouldn't be self-explaining any more. |
|
As long as I'm working with Java, I could defined constants within a class, so instead of integer values, I could use constants like State.PENDING or State.FINISHED. |
|
Is it possible to create such constants directly in Oracle, so I can use them within SQL-queries like select * from jobs where state = State.PENDING ? |
ld.state = 'pending' then
ld.state = 'finished' then
ld.state = 'pending' then
ld.state = 'finished' then|
Regards Marten |
#3
| |||
| |||
|
|
Hello, currently, we are using strings like "pending" or "finished" in some tables to specify the state of certain jobs stored in these tables. These values are self-explaining. These columns are indexed, of course. But I guess, lookups of jobs with certain states would be much faster, if the states would be stored is integer values, e.g. pending = 1, finished = 2 and so on. However, these values wouldn't be self-explaining any more. As long as I'm working with Java, I could defined constants within a class, so instead of integer values, I could use constants like State.PENDING or State.FINISHED. Is it possible to create such constants directly in Oracle, so I can use them within SQL-queries like select * from jobs where state = State.PENDING ? Regards Marten |
#4
| |||
| |||
|
|
Hello, currently, we are using strings like "pending" or "finished" in some tables to specify the state of certain jobs stored in these tables. These values are self-explaining. These columns are indexed, of course. But I guess, lookups of jobs with certain states would be much faster, if the states would be stored is integer values, e.g. pending = 1, finished = 2 and so on. However, these values wouldn't be self-explaining any more. As long as I'm working with Java, I could defined constants within a class, so instead of integer values, I could use constants like State.PENDING or State.FINISHED. Is it possible to create such constants directly in Oracle, so I can use them within SQL-queries like select * from jobs where state = State.PENDING ? Regards Marten |
#5
| |||
| |||
|
|
The chance of you having enough activity on these tables to be able to measure the difference between your strings and an integer is remarkably close to zero. |
#6
| |||
| |||
|
|
On Thu, 29 Nov 2007 16:44:20 +0100, Marten Lehmann lehmannmapson (AT) cnm (DOT) de> wrote: Hello, currently, we are using strings like "pending" or "finished" in some tables to specify the state of certain jobs stored in these tables. These values are self-explaining. These columns are indexed, of course. But I guess, lookups of jobs with certain states would be much faster, if the states would be stored is integer values, e.g. pending = 1, finished = 2 and so on. However, these values wouldn't be self-explaining any more. As long as I'm working with Java, I could defined constants within a class, so instead of integer values, I could use constants like State.PENDING or State.FINISHED. Is it possible to create such constants directly in Oracle, so I can use them within SQL-queries like select * from jobs where state = State.PENDING ? Regards Marten If you do switch to numbers, a VIEW can be used that automatically changes the numbers to words, either with a CASE expression, or by joining to a TABLE that defiunes them. Then, the search could be directly on the words. |
#7
| |||
| |||
|
#8
| |||
| |||
|
|
To your first question, as others have said, it is not likely to make a difference. If the word defines a well known state, and the name will never change, it is just fine. A lookup table may be nice, but that depends on the way it is used. |
#9
| |||
| |||
|
|
On 29.11.2007 18:33, Brian Tkatch wrote: On Thu, 29 Nov 2007 16:44:20 +0100, Marten Lehmann lehmannmapson (AT) cnm (DOT) de> wrote: Hello, currently, we are using strings like "pending" or "finished" in some tables to specify the state of certain jobs stored in these tables. These values are self-explaining. These columns are indexed, of course. But I guess, lookups of jobs with certain states would be much faster, if the states would be stored is integer values, e.g. pending = 1, finished = 2 and so on. However, these values wouldn't be self-explaining any more. As long as I'm working with Java, I could defined constants within a class, so instead of integer values, I could use constants like State.PENDING or State.FINISHED. Is it possible to create such constants directly in Oracle, so I can use them within SQL-queries like select * from jobs where state = State.PENDING ? Regards Marten If you do switch to numbers, a VIEW can be used that automatically changes the numbers to words, either with a CASE expression, or by joining to a TABLE that defiunes them. Then, the search could be directly on the words. You are sure this is faster? How would introducing one more layer of indirection make this faster? Am I missing something? |
|
Cheers robert |
#10
| |||
| |||
|
|
Hello, To your first question, as others have said, it is not likely to make a difference. If the word defines a well known state, and the name will never change, it is just fine. A lookup table may be nice, but that depends on the way it is used. would you say the same is true for joins? What would be faster, this one? domains ------- name (pk) ... records ------- id (pk) name (fk) ... for a query like select * from domains d, records r where d.name = r.name and d.name = 'whatever' or this one: domains ------- id (pk) name (unique) ... records ------- id (pk) domain_id (fk) ... for a query like select * from domains d, records r where d.id = r.domain_id and d.name = 'whatever' Mathematically it should be faster to compare two 4 byte non-zero integer values than two at least 8 byte strings. But the first solution is more elegant and intuitive. |
|
Regards Marten |
![]() |
| Thread Tools | |
| Display Modes | |
| |