How to improve the performance of the query?

Is it adviceable to keep all the columns in a table present in Oracle database as primary key or only putting index to the columns which are being used in query without any primary key?

  • A table present in Oracle database which will be having information about flights. According to the functionality of the table, only possibility of having primary key is by keeping all the columns as a primary key. Because it may contain duplicate values in all the columns except any one column in a given time which may vary for different records. The table is having 10 columns. Which will improve the performance, either keeping all the columns as primary key or keeping index for the columns used in query without having any primary key...

  • Answer:

    You should always have a primary key in a table. In that case, I would never use 10 columns, but instead use an integer field with automatic numbering. To do that in Oracle, use either a trigger or a sequence which will automatically populate the primary key. See Oracle documentation: http://www.orafaq.com/wiki/AutoNumber_and_Identity_columns You probably should also create an index on the table to increase performance.

Erik Laliberte at Quora Visit the source

Was this solution helpful to you?

Other answers

This smells like a table built by a Java guy based on his object model. Instead, model the data based on the data. I know a little bit about flight data and I do not believe such a table really exists. If the app would like a 10 column view of the data that is fine. Abstract the data model accordingly for the OM. To answer your question, in Oracle (and Postgres), 99.9% of the time I have a system generated numeric surrogate primary key, and a unique key index on the alternate key (aka business key) to enforce uniqueness. There are exceptions when I dont follow this but I can not think of any that apply to fight data when modeled properly.

Andrew Hansen

No, it is not. Because the index will be huge and useless. If you index columns A,B,C,D,E, all the queries which do not have A as a condition will not be able to use the index.

Lucian Nutiu

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.