Varchar2 vs. Raw for hex values
556095Feb 22 2010 — edited Feb 23 2010I'm working with a database (10.2.0.3.0 (32-bit Windows)) that needs to store a large number of 128-bit hexadecimal values. The two obvious candidates for these fields are RAW and VARCHAR2. RAW seems to be the more natural choice, as it is designed for storing binary data. There would seem to be less storage overhead and it will act as a constraint, ensuring that only hex values are inserted.
However, a simple test makes me wonder if there will be a performance issue related to using the RAW datatype. I created a table with both VARCHAR2 and RAW columns, then populated them with 2000 sets of hex values (each row contained the same value in both fields, but each row is unique). I then created an index on each column and compared the explain plan for selecting a value from each column (using hextoraw for the RAW column, to ensure that the index is used). For unique indexes, the cardinality is identical for both plans. However, for non-unique indexes the RAW index assumed a cardinality of 8 for the index and 20 for the table access, whereas the VARCHAR2 index correctly identified the cardinality as 1.
Am I correct in thinking that, for this data, a VARCHAR2 column is going to scale better than a RAW column? Also, does anyone know why this is?
--
Allan