Home > Ask the Oracle Database / Applications Experts > Oracle database design and architecture Questions & Answers > Better performance with varchar2(1) or number(1)?
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Better performance with varchar2(1) or number(1)?

Brian Peasland EXPERT RESPONSE FROM: Brian Peasland

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site


Oracle tips, scripts, and expert advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


>
QUESTION POSED ON: 03 February 2006
Since Oracle table structures do not support a boolean datatype, I am faced with a choice (make it a varchar2(1) or number(1)), with contents of Y,N or 1,0. The questions I have are:
  1. From a comparison perspective, which provides better performance? Comparison of a number or string?
  2. Which solution takes up less storage? Number(1) or varchar2(1)?
  3. The results will be mapped into a J2EE data structure supporting a boolean datatype. Which method (from a performance perspective) is better, number to boolean or DECODE(boolstring, 'Y', 1, 'N', 0)?
Many thanks in advance for your thoughts!

>

For almost every circumstance, comparing numbers or strings will make very little difference to the performance of your application. You will most likely find that using one datatype or the other will not impact your application in any noticable way. There are many other aspects of application performance (such as disk contention or poorly written SQL) that can have a very noticable impact on your application's performance.

The VARCHAR2(1) datatype specification will take up to one byte of storage space. The NUMBER(1) datatype will take at least two bytes since numbers have to store both the exponent and the mantissa of the number's representation. That being said, it is my opinion that worrying about storage requirements at this level takes more effort than it is worth. You will not realize much from your work.

I am not 100% sure how J2EE will be impacted by NUMBER to BOOLEAN or using DECODE as you have suggested. But it should be very simple for you to create a test case. In your J2EE application, query the data from one table that stores the value as a NUMBER and then do the same operation with VARCHAR2(1). Time the operations using Java's timing routines. Which works faster? Do not forget to run the test case multiple times so as to obtain an average and remove a bad run's anomolies. I will bet you will find that there is very little difference in the overall runtimes.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



RELATED CONTENT
Oracle database design and architecture
How to use V$SEGMENT_STATISTICS to find the most accessed Oracle table
Can I install an Oracle client on Windows 7?
How to use the Oracle Database Upgrade Assistant (DBUA)
Can I specify Oracle column order in my database table?
Can I have a single Oracle 11g RAC instance across multiple databases?
How to use the Oracle export utility to duplicate database structure
How to choose the primary key columns in an Oracle table
Understanding the data archiving definition
How to plan Oracle Grid Control Repository maintenance
What Linux flavor should I use for my Linux proof of concept in Oracle?

Oracle database design and architecture
How to use V$SEGMENT_STATISTICS to find the most accessed Oracle table
Can I install an Oracle client on Windows 7?
How to use the Oracle Database Upgrade Assistant (DBUA)
Can I specify Oracle column order in my database table?
Can I have a single Oracle 11g RAC instance across multiple databases?
How to use the Oracle export utility to duplicate database structure
How to choose the primary key columns in an Oracle table
Understanding the data archiving definition
Review: Oracle's 11g R2 database has some good and bad
Scaling an Oracle database: What is the best strategy for you?

Oracle database performance problems and tuning
Oracle releases new database, says 11g upgrade will cut costs
Oracle raises prices on database management packs
Oracle New Year's resolutions, part 1: Advice for navigating 2009
Solving common Oracle errors guide
Oracle 11g data compression
Varchar or number for better performance?
Do statistics on SYS-owned objects hurt performance in 10g?
Inside the Oracle 11g SQL Performance Advisor, part 1
Inside the Oracle 11g SQL Performance Advisor, part 2
Difference between driving table and driver table in Oracle

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
E. F. Codd  (SearchOracle.com)
extent  (SearchOracle.com)
flexfield  (SearchOracle.com)
foreign key  (SearchOracle.com)
multidimensional database  (SearchOracle.com)
object-oriented database management system  (SearchOracle.com)
quad tree  (SearchOracle.com)
relational online analytical processing  (SearchOracle.com)
row  (SearchOracle.com)
splay tree  (SearchOracle.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Oracle White Papers: Fusion Middleware
HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2003 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts