Is DISTINCT a Bug?
In your application or data model that is.
On a well designed system, I've rarely seen the need to use DISTINCT.
If anything, I use it to do analysis on table data or maybe a summary report. Something like this:
SELECT
COUNT( DISTINCT( col_1 ) ) col1_count,
COUNT( DISTINCT( col_2 ) ) col2_count,
COUNT( DISTINCT( col_3 ) ) col3_count,
COUNT(*) count_all
FROM my_table;
That will tell me the basic distribution of certain data elements in a specific table. Good for possibly determining whether a column needs a Bitmap Index.
In an OLTP system however, the liberal use of DISTINCT signals (to me) a problem in the underlying model. Obviously not all instances are without merit, but I'd be willing to bet that the majority
are an indicator.
How about you? What are you thoughts on DISTINCT? Good? Bad? Indifferent?
Labels: database, design, rant, sql