Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7588077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:50:03+00:00 2026-05-30T19:50:03+00:00

I have to make my query on large database (Snort alerts) to find duplicate

  • 0

I have to make my query on large database (Snort alerts) to find duplicate entries. However, I came up with bellow query, but it takes so many time to be executed!

SELECT sid, cid, timestamp, sig_name, inet_ntoa(ip_src), layer4_sport,
       inet_ntoa(ip_dst), layer4_dport
  FROM DB
 WHERE (ip_dst IN
        (SELECT ip_dst FROM DB GROUP BY ip_dst HAVING count(*) > 1)
   AND timestamp IN
        (SELECT timestamp FROM DB GROUP BY timestamp HAVING count(*) > 1)
   AND layer4_dport IN
        (SELECT layer4_dport FROM DB GROUP BY layer4_dport HAVING count(*)>1 ))

The above query trying to find alerts ip_dst that has same timestamp and layer4_dport
if the they came more than one time. I hope its clear!

Any tips or tricks to make it efficient?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:50:04+00:00Added an answer on May 30, 2026 at 7:50 pm

    I’ve formatted your query… if we break it down you seem to be applying a couple of functions inet_ntoa. If you don’t have a pressing need for then get rid of them ( especially if they look at a table ).

    Secondly, if we look at your query you are doing a full scan of DB 3 times for your various counts, and then at the very minimum a range scan in your top level select.

    SELECT sid, cid, timestamp, sig_name, inet_ntoa(ip_src), layer4_sport, inet_ntoa(ip_dst), layer4_dport 
      FROM DB 
     WHERE ( ip_dst IN ( SELECT ip_dst 
                           FROM DB 
                          GROUP BY ip_dst 
                         HAVING count(*) > 1 ) 
       AND timestamp IN ( SELECT timestamp 
                            FROM DB 
                           GROUP BY timestamp 
                          HAVING count(*) > 1 ) 
       AND layer4_dport IN ( SELECT layer4_dport 
                               FROM DB 
                              GROUP BY layer4_dport 
                             HAVING count(*) > 1 ) 
            ) 
    

    By not linking your subquery back to the main table, you’ve assumed that ip_dst, timestamp and layer4_dport are each unique across the whole table and then are trying to find where the unlikely occurrence of 3 independently unique values happened to have duplicates in the same row.

    I suspect what you want to do is something like the following:

    SELECT a.sid, a.cid, a.ip_dst, a.timestamp, a.sig_name, a.layer4_sport, a.layer4_dport 
      FROM DB a 
      JOIN ( SELECT timestamp, layer4_dport 
               FROM DB 
              GROUP BY timestamp, layer4_dport
             HAVING count(*) > 1 ) b
        ON a.timestamp = b.timestamp
       AND a.layer4_dport = b.layer4_dport
    

    This finds you all the rows where there are more than 1 identical timestamp and layer4_dport combinations as per your question.

    If you want to find all the duplicates at the level of ip_dst then you need to add this to your sub-query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 tables, and I want to make a query for a search
I have identified the query constructs my users normally use. Would it make sense
I have to make a decision of which database server to use for my
I have a large xml file (1Gb). I need to make many queries on
I'm gettint a large amount of data from a database query and I'm making
I have a result set I pull from a large database: $result = mysql_query($sql);
I have a query returning large XML, its size can reach 1GB in extreme
In SQL Server 2005, I have a query that involves a bunch of large-ish
In trying to determine what area of a large query i have is causing
I need to perform a LINQ query on a large database in C#. One

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.