Skip to Main Content
  • Questions
  • BTree Index or Bitmap Index on Financial Transactions Table

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Emad.

Asked: August 21, 2017 - 2:27 pm UTC

Last updated: August 24, 2017 - 3:49 pm UTC

Version: 11G2

Viewed 1000+ times

You Asked

Hi Tom,

I need some advices on correct bitmap selection.

We have a table with 200,000,000 Records of some payment cards transactions. Each transaction has a unique CardSerialNumber and a TransactionCounter which is generated by the card itself, so we would like to have no duplicate CardSN+TransCounter in the table.
We have 2,000,000 Cards so the Count(distinct CardSN) <= 2,000,000
And counter is 1,2,3,...

So My Question:
1- Which one is better: Either Unique BTree index on both fields or Unique Bitmap Index on them?
2- Does a Bitmap Index on the table and a unique constraint working together ?
3- Is this method more suitable: Allow to insert duplicate rows, and delete them at the end of day?

Thank you

and Chris said...

1. You can't have unique bitmaps indexes. So a unique B-tree index is infinitely better.

2. Not sure what you mean? You can have a bitmap index and unique constraint on different columns in a table:

create table t (
  c1 int unique, 
  c2 int
);

create bitmap index i2 on t(c2);


But you can't use a bitmap index to support a unique constraint:

alter table t add constraint u unique (c2) using index i2;

ORA-14196: Specified index cannot be used to enforce the constraint.


3. No! You're creating extra work for yourself. And you have a period of time with bad data. You want to stop bad data arriving in the first place.

If you want to know more about the differences between bitmaps and B-trees, check out my latest post on indexes:

https://blogs.oracle.com/sql/how-to-create-and-use-indexes-in-oracle-database

Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

1st

A reader, August 21, 2017 - 5:32 pm UTC

Before your must tell us if the table is updated and how ? Is the table for oltp dwh or both transactions.
First idea that comes up is the table partitioned ?
If not I suggest a partitioning on cardsn interval if number otherwise why not hash 64. Then tune to look for a global partition index on cardsn+trans#
This works d'or the pk index as the cardsn is the key partition.
Lot of solutions around . why not a virtual col if the cardsn is numeric varchar2 to convert into number for interval partitioning. ..
Chris Saxon
August 22, 2017 - 1:09 pm UTC

What's partitioning got to do with this? The OP was asking about enforcing uniqueness...

Type of transactions

Emad, August 22, 2017 - 4:41 pm UTC

Thank you guys

Transactions are OLTP and table is partitioned with hash of cardsn

I used partitioned index because all searches are with cardsn and transactionid

The key is Reference number, an always unique number from bigbang till the end and its used also in many searches more than cardsn.

I have a unique constraint on cardsn+transactionid

The question was is this method good or bad.

The TPS in peak time is 40K and 40,000,000 transactions a day

Cardsn is raw(4) so threated as unsigned int number

I would like to know if a bitmap index on transaction id will help insertion or not

This table is not used for reporting. A more indexed tabled of same data is used for reporting

Any more data?
Chris Saxon
August 24, 2017 - 1:10 pm UTC

Is what good or bad? Having a unique constraint?

If cardsn+transactionid is unique, then YES! this is a fantastic idea!

As cardsn is your partitioning key, you could make the index for this constraint locally partitioned too.

I would like to know if a bitmap index on transaction id will help insertion or not

No. No indexes will "help insertion". In fact, you've given the database more work to do. It now has to update the index as well as add the data.

Emad, August 24, 2017 - 1:15 pm UTC

Thank you chris. Yep i used local index as I call it partiotioned index.

I tought that a bitmap index on transactionid will help insertion because it can easily checks wheter if its unique or duplicate

As you mentioned the current index is fast enough and I will not use an additional bitmap index.

Regards


CLOSED
Chris Saxon
August 24, 2017 - 3:49 pm UTC

Thank you CLOSED

More to Explore

Design

New to good database design? Check out Chris Saxon's full fundamentals class.