Does the multiplication factor of a column's length somehow influence the database performance?
In other words, what is the difference between the performance of the following two tables:
TBL1:
- CLMN1 VARCHAR2(63)
- CLMN2 VARCHAR2(129)
- CLMN3 VARCHAR2(250)
and
TBL2:
- CLMN1 VARCHAR2(64)
- CLMN2 VARCHAR2(128)
- CLMN3 VARCHAR2(256)
Should we always attempt to make a column's length to some power of 2
or does only the maximum size matter?
Some of the developers claim that there is some link between the multiplication factor of the length of the columns in a database, because it influences how Oracle distributes and saves the data on the disk and shares its cache in memory. Can someone prove or disprove this?
There is no difference in performance. And there are no hidden optimizations done because of power of 2.
The only thing that does make a difference in how things are stored is the actual data. 100 characters stored in a
VARCHAR2(2000)
column are stored exactly the same way as 100 characters stored in aVARCHAR2(500)
column.Think of the length as a business constraint, not as part of the data type. The only thing that should driver your decision about the length are the business constraints about the data that is put in there.
Edit: the only situation where the length does make a difference, is when you need an index on that column. Older Oracle versions (< 10) did have a limit on the key length and that was checked when creating the index.
Even though it's possible in Oracle 11, it might not be the wisest choice to have an index on a value with 4000 characters.
Edit 2:
So I was curious and setup a simple test:
Then filled both tables with strings composed of 40 'X'. If there was indeed a (substantial) difference between the storage, this should show up somehow when retrieving the data, right?
Both tables have exactly 1048576 rows.
So the full table scan for both tables did exactly the same. So what happens when we actually select the data?
There is a slight difference in consistent gets, but that could be due to caching.