Programmer/DBA ques...
 

  You don't need to be an 'investor' to invest in Singletrack: 6 days left: 95% of target - Find out more

[Closed] Programmer/DBA question

15 Posts
8 Users
0 Reactions
62 Views
 Earl
Posts: 1902
Free Member
Topic starter
 

I'm working on a system that has a table with the following indexes:

Index 1. PK
AttrubuteA
AttrubuteB
AttrubuteC

Index 2. Unique
AttrubuteA
AttrubuteB

I want to remove the unique constraint on Index 2 as its causing problems -
occasionally.
But I'm trying to understand why the original programmer made Index 2 unique. Any ideas?


 
Posted : 02/10/2017 6:27 pm
Posts: 3171
Free Member
 

The first question to ask is what makes a unique row in the table.


 
Posted : 02/10/2017 6:33 pm
Posts: 31206
Full Member
 

Does seem a bit odd. If Index2 uniquely identifies a row with two atttibutes then that sounds it should be the primary key. If it doesn't then it can't be unique.


 
Posted : 02/10/2017 6:51 pm
Posts: 7656
Full Member
 

Any ideas?

Because they thought it would be required to enforce the business logic.
Not a particularly helpful answer but without knowing the business specifics its impossible to answer.
How is it causing issues?


 
Posted : 02/10/2017 6:51 pm
Posts: 3171
Free Member
 

And just to add, if you remove the unique constraint from index 2 then it is superfluous and can be removed completely.


 
Posted : 02/10/2017 6:54 pm
Posts: 1156
Free Member
 

developers love indexes (indices? -indexes just sounds wrong to me). That and functions. I bleeding hate functions; saved 35 mins on one process changing from a function to a simple table lookup.

i have one table in one DB that has 150Gb of data and 560Gb of indexes. They refuse to entertain the thought of removing them, despite me showing they're not used.

Which brings me to my main point (sorry, rambling). Check whether the index is being used [url= https://www.mssqltips.com/sqlservertutorial/256/discovering-unused-indexes/ ]here[/url]; if not, get rid. If it is, you can tell what is using it, and then see whether that should.


 
Posted : 02/10/2017 7:12 pm
 Earl
Posts: 1902
Free Member
Topic starter
 

The PK does uniquely identify the record - 100% sure of that.

On the system I'm working on, a index is required if one wants to retrieve in that seq (sounds crazy but its true - I think its a throwback from AS400 days). Its not necessary there for performance. So Index 2 is probably used somewhere in the application/business logic. However I can't see why it need to be unique.

I think the original developer made a boo boo.


 
Posted : 02/10/2017 7:32 pm
Posts: 3171
Free Member
 

The PK does uniquely identify the record - 100% sure of that.

In which case index 2 is enforcing a different constraint to the PK and it should be removed.

The existing PK will still utilise the index if only column A and B are provided.


 
Posted : 02/10/2017 7:42 pm
 Earl
Posts: 1902
Free Member
Topic starter
 

What problems is it causing?

The majority of the time - jut AttributeB alone is enough to be a alternate key. Once in a very blue moon - its not.

Were looking at making a change to the system where the blue moon could happen much more often.

Index 2 has been on the system for 15 years at least. It has caused problems in the past - and there have been bandaids and work-arounds applied. No one has suggested to just remove the unique constraint - because no one has taken the time to try and understand it....until now.


 
Posted : 02/10/2017 7:43 pm
 Earl
Posts: 1902
Free Member
Topic starter
 

Thanks all - I'll recommend the unique constraint be removed.


 
Posted : 02/10/2017 7:47 pm
Posts: 3171
Free Member
 

I'll recommend the unique constraint be removed.

Remove the index completely - it's not needed.


 
Posted : 02/10/2017 7:50 pm
Posts: 1156
Free Member
 

if you need it for the retrieval of data in sequence (DB2?), are you sure that data sequence doesn't care about the uniqueness of C, but needs it for A and B? Without knowing DB2 too well, it's hard to tell, but it is superfluous from a T-SQL aspect.


 
Posted : 02/10/2017 7:58 pm
 Earl
Posts: 1902
Free Member
Topic starter
 

I hear ya but can't do that - Somewhere in the system it will be hard coded to use Index 2. If I remove it the app will fail to execute irrespective of whether the DB uses it or not for the fetch.

Cheers.


 
Posted : 02/10/2017 7:58 pm
Posts: 10315
Full Member
 

Is it possibly not being used as an index but is rather a cheat to ensure you only ever have one value of attribute C for a pair of attribute A & B? If you remove it then you have the possibility of more than one value of C and maybe that is the no no?


 
Posted : 02/10/2017 8:02 pm
Posts: 3378
Full Member
 

But I'm trying to understand why the original programmer made Index 2 unique. Any ideas?

Have you read the documentation.
[img] [/img]


 
Posted : 03/10/2017 8:33 am
Posts: 0
Free Member
 

Been a long time since I had anything to do with DB2 but, could it be that when the table was originally set up it was thought that A,B and C were required to make a row unique, but at a later date it was realised that actually only A, and B were required. If it's a large table changing the primary key of a table can be very time consuming and could mean down time or delays you couldn't afford, but adding a new index that effectively enforces A and B as a unique key for a record would be done in the background and not have any significant affect on the systems performance while it was being created...


 
Posted : 03/10/2017 8:49 am

6 DAYS LEFT
We are currently at 95% of our target!