473,387 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How efficient are queries that use DISTINCT (vs filtering data yourself)

57
I have a query on a database that returns a large number of rows from a database (somewhere near a million) to an application that then does some processing with them. Some of these returns may be duplicates, and I considered using DISTINCT to make sure these duplicates do not occur, however I suspect I would be better off filtering the duplicates within the application, rather than within the database.

My justification would be as follows:
- Using DISTINCT means the entire query needs to complete before any results are returned
- Filtering myself means the results will start to be returned almost immediately, so I can be processing the results as the query is still executing.

Just wondering whether people more familiar with how databases (in particular Oracle) work.

(This application is written in C#, however I suppose the bigger point is questioning whether there's any point using 'distinct' in a cursor (other than in a sub-query) in any language....)
May 18 '11 #1
3 2444
rski
700 Expert 512MB
Did you try to optimize the query in any way?
Is it very complex query? Did you check explain plan for it?
I think that processing 1mln rows from the application will also be very time consuming. How do you want to code that distinct in application(using some hash table?)?
May 19 '11 #2
Brosert
57
1) Not sure what you mean by optimisation. I am making sure that where possible, indexes are being used for joins (the data was designed to be queried roughly how I query it)
2) The query joins on 3 tables, but I wouldn't consider it overly complex
3) No I did not have a look at the explain plan, because I didn't really think it was overly relevant to the question - I hoped someone might discuss whether on the whole they think it more efficient to use distinct or filter in the app.
4) 1 million rows may be time consuming either way, but the specific question I was interested in is whether using DISTINCT is likely to be more or less efficient than filtering Application side.

For the record, I have found that in this case at least, it seems a lot more efficient to filter in the application rather than on the database - and is far more flexible
Oct 12 '11 #3
rski
700 Expert 512MB
4) yes, but if you do filtering on the application side you will have to send 1mln rows to the application and it is wrong from the performance point of view. If you can do something with the database (like get distinct columns) you should do that.
Oct 14 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Henry | last post by:
Hi experts of Oracle, I used Oracle for small queries, but now I have a task to create WEB-based report by getting data, summarying ( several counts, min and max) and re-formatting, where the...
0
by: Tony Stephens | last post by:
I have a database table that contains a set of numbers (set X). I need to be able to generate/export a random set of survey numbers (set C) from set A with IDs that aren't in set B. Where set A is...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
5
by: hubmei75 | last post by:
Hello, I have a simple table containing adresses. A sample view of the table is id name city -------------------------------- 100 Meier New York 101 Meier Tokyo 110 ...
1
by: vncntj | last post by:
the problem i'm having is that i can't get the Sql statement set to search for Department or Last_Name%.. :( <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$...
3
by: Shawn Ramirez | last post by:
As with most web applications speed is a huge deal to me in my applications. My customers don't really care if my app is a true 3 tier application or not, they just want it to be faster then it was...
0
by: Christoph Haas | last post by:
Hi, list... I have written an application in Perl some time ago (I was young and needed the money) that parses multiple large text files containing nested data structures and allows the user to...
5
by: AtCor | last post by:
SELECT , Date, , Time FROM (SELECT ISNULL(t9., t8.) AS , ISNULL(t9.Date, t8.Date) AS Date, ISNULL(t9.Rows, t8.Rows) AS Rows, c., c.Time, ROW_NUMBER() OVER (PARTITION BY ISNULL(t9., t8.),...
21
by: Cyrax1033 | last post by:
I'm new to MS Access 2000 and have been working on a project that calls for retrieving filtered information. I have a form that had 3 checkboxes that would filter records based off them being...
6
by: nairda | last post by:
Hi there, I need help processing data from Excel in VB. I have a MSHFlexgrid to show data extracted from Excel. I'm able to show a range of cells from Excel table to my Flexgrid, but that's it. The...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.