473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

String vs Numeric Type

would it matter if I decided to make a primary key a string of numbers
vs actual numbers ? would it make any difference to DB2 in terms of
efficiency ? why would you choose numeric over a string for a key that
does not need to be in numeric format ?

thanks
--
reply to newsgroupsurferATyahooDOTcom
Nov 14 '05
54 6226
kenfar wrote:
Serge,

Couple of comments:
1. How do you enforce the functional dependency?

Hmm, I've never seen anyone attempt to enforce functional dependency
between an artificial & natural key. Is there a method that you had in
mind for this? Note, that I haven't found this to be a serious source
of data quality problems either tho...

It's not enforcable. That's the point. Maybe you haven't found serious
problem because you have no means detecting them... ;-)
Not trying to scaremonger.. just to make you (and no doubt others) think
about the consequences of design choices.
2. How do you index? I presume your app wants to see the natural key,
yet your joins operate on the abstract key. That means that you end up
with ISCAN-FETCH combinations instead of pure ISCAN on covering indexes.
You have traded lazy fingers for performance.

Is it really that bad? Many of the queries that I have that use
artificial ids also refer to non-key attributes in the query anyway.
These wouldn't benefit from the natural key, but the index io certainly
must benefit from use of a 4-byte smallint vs composit key with
multiple large varchars.

SMALLINT is 2 byte.... ;-)
Anyway. Check out the INCLUDE clause on unique indexes.
As you say.. disk is cheap who cares for one extra level in the index.
Won't bother your bufferpool much either.
When creating a table you can create a unique index on the PK columns
with INCLUDE columns first. THEN add teh primary key attribute. DB2 will
pick up the unique index (raisinng a warning to tell you).
This way you can get covering index access for your common queries.
Plus, these days labor costs so much more than hardware, and business
rules change so fast, that the future-proofing you get from artificial
keys can be worth any theoretical performance problem. I know one
system that has business rule changes every month - as new customers
with slightly different needs are added, new source systems are fed
into it, etc. Assumptions made about natural keys for one set of data
often fails when the next set is added. This is a data warehouse,
which is much more susceptible to this kind of a problem than a small
OTLP database though.

OK. There are "good" designed warehouses out there with substitute keys.
I buy it for a warehouse much more willingly than for OLTP.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 30 '05 #51
> It's not enforcable. That's the point. Maybe you haven't found serious
problem because you have no means detecting them... ;-)
Not trying to scaremonger.. just to make you (and no doubt others) think
about the consequences of design choices.
Sure, great point. The one place I've seen this actually happen is in
OLTP systems in which a user adds a new entry by updating non-key
valuesth new values (rather than deleting the first and adding the
second). This can cause quite a mess with historical data, security,
etc as you can imagine. This can happen with natural keys as well,
just less likely I suppose.
SMALLINT is 2 byte.... ;-)
dang, i had changed that after i wrote it thinking that smallint was an
exaggeration, but only changed the length not the name: i've used
smallint often, but sure enough I've now got a database with 40 tables
that need a migration from smallint to integer. The table was never
intended to be this large, but requirement change. And the conversion
will be a total and unnecessary pain in the butt.
When creating a table you can create a unique index on the PK columns
with INCLUDE columns first. THEN add teh primary key attribute. DB2 will
pick up the unique index (raisinng a warning to tell you).
This way you can get covering index access for your common queries.


will keep that in mind, thanks

Ken

Nov 30 '05 #52
kenfar wrote:
dang, i had changed that after i wrote it thinking that smallint was an
exaggeration, but only changed the length not the name: i've used
smallint often, but sure enough I've now got a database with 40 tables
that need a migration from smallint to integer. The table was never
intended to be this large, but requirement change. And the conversion
will be a total and unnecessary pain in the butt.

You can imagine how big of a pain is in my case. We have a database with
over 1500 tables. And I would have to change about 400 tables and go from
DECIMAL(18, 2) to DECIMAL(30, 15) for about 1500 columns. :) :) :) :)

I hope new version of DB2 on LUW will allow me to do something like:
ALTER TABLE A CHANGE COLUMN F SET DATA TYPE DECIMAL (31, 15).
Serge ? :) :) :)
When creating a table you can create a unique index on the PK columns
with INCLUDE columns first. THEN add teh primary key attribute. DB2 will
pick up the unique index (raisinng a warning to tell you).
This way you can get covering index access for your common queries.


will keep that in mind, thanks


Yes, this is worth keeping in mind :)

Ken


Best regards,
Kovi

-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
| Gregor Kovac | Gr**********@mikropis.si
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~

Dec 1 '05 #53
Gregor KovaÄŤ wrote:
kenfar wrote:

dang, i had changed that after i wrote it thinking that smallint was an
exaggeration, but only changed the length not the name: i've used
smallint often, but sure enough I've now got a database with 40 tables
that need a migration from smallint to integer. The table was never
intended to be this large, but requirement change. And the conversion
will be a total and unnecessary pain in the butt.
You can imagine how big of a pain is in my case. We have a database with
over 1500 tables. And I would have to change about 400 tables and go from
DECIMAL(18, 2) to DECIMAL(30, 15) for about 1500 columns. :) :) :) :)

And of course you ahev been using USER DEFINED DISTINCT DATATYPES to at
least script thsi so much easier.... ;-)
Sorry petpeeve - trying to teach DBAs what app developers have found
out about years ago: typedef.
I hope new version of DB2 on LUW will allow me to do something like:
ALTER TABLE A CHANGE COLUMN F SET DATA TYPE DECIMAL (31, 15).
Serge ? :) :) :)

Well, have you been good this year? If not Viper just might bring a lump
of coal.
(date for DB2 x-mas is not included)

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Dec 1 '05 #54
Serge Rielau wrote:
Gregor Kovač wrote:
kenfar wrote:

dang, i had changed that after i wrote it thinking that smallint was an
exaggeration, but only changed the length not the name: i've used
smallint often, but sure enough I've now got a database with 40 tables
that need a migration from smallint to integer. The table was never
intended to be this large, but requirement change. And the conversion
will be a total and unnecessary pain in the butt.
You can imagine how big of a pain is in my case. We have a database with
over 1500 tables. And I would have to change about 400 tables and go from
DECIMAL(18, 2) to DECIMAL(30, 15) for about 1500 columns. :) :) :) :)

And of course you ahev been using USER DEFINED DISTINCT DATATYPES to at
least script thsi so much easier.... ;-)
Sorry petpeeve - trying to teach DBAs what app developers have found
out about years ago: typedef.


Hmm.. We do have our data types defined in our logical database model
(PowerDesigner), but they are not propageted into our phisical model. Don't
ask me why.
I hope new version of DB2 on LUW will allow me to do something like:
ALTER TABLE A CHANGE COLUMN F SET DATA TYPE DECIMAL (31, 15).
Serge ? :) :) :)

Well, have you been good this year? If not Viper just might bring a lump
of coal.
(date for DB2 x-mas is not included)


Yes, I have been a very, very good boy (take my word, don't ask my
mother :) )
Cheers
Serge


--
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
| Gregor Kovac | Gr**********@mikropis.si
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Dec 5 '05 #55

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Owen Jacobson | last post by:
Salve. Does anyone have any suggestions for writing a portable 'byte' numeric type? I'm aware that (signed) char is a numeric type and can be used as such, and I assume this is the fundamental...
1
by: Nagib Abi Fadel | last post by:
Hi, does specifiying the precision and the scale of a numeric type increases the speed of calculations on a column of that type ??? (I read the docs : nothing mentioed about that.) Thx
4
by: Ken Varn | last post by:
I have an unknown numeric Type object passed into a function. I want to run a conversion on a string to convert the string to that Type object and return an object of that type. Is there some way...
6
by: M.A. Oude Kotte | last post by:
Hi All, I hope this is the correct mailing list for this question. But neither postgresql.org nor google could help me out on this subject. I did find one disturbing topic on the mailing list...
2
by: Frank | last post by:
Hello, I am attempting to retrieve a numeric type froma a table. I get an invalid cast exception when I use the following code in my data layer: //The problem definitley occurs in the...
2
by: Brian Tkatch | last post by:
>A) If you have a 17-way join where the aliases are all one letter, >you should fire all your programmers and get people who think. My DBA slammed this at me when he saw i did that with a 14-way...
4
by: Hyun-jik Bae | last post by:
Is that not allowed to assume generic type numeric type? As far as I've tried, I got an error with the following code: public class AAA<T> { public int Foo(T a) { return a; // error: Cannot...
5
by: Andreas Beyer | last post by:
There has been quite some traffic about mutable and immutable data types on this list. I understand the issues related to mutable numeric data types. However, in my special case I don't see a...
2
by: CoreyWhite | last post by:
Problem: You have numbers in string format, but you need to convert them to a numeric type, such as an int or float. Solution: You can do this with the standard library functions. The...
3
by: aris1234 | last post by:
Hi.. i have field in record using type : numeric, how to make validation and i want viewing messagebox if user inputing character or empty? this code just work for empty field, not for numeric...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.