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 6006289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:31:04+00:00 2026-05-23T01:31:04+00:00

I need some options. I have a table layed out as follows with about

  • 0

I need some options.

I have a table layed out as follows with about 78,000,000 rows…

  • id INT (Primary Key)
  • loc VARCHAR (Indexed)
  • date VARCHAR (Indexed)
  • time VARCHAR
  • ip VARCHAR
  • lookup VARCHAR

Here is an example of a query I have.

SELECT lookup, date, time, count(lookup) as count FROM dnstable
WHERE STR_TO_DATE(`date`, '%d-%b-%Y') >= '$date1' AND STR_TO_DATE(`date`, '%d-%b-%Y')   <= '$date2' AND
time >= '$hour1%' AND time <= '$hour2%' AND
`loc` LIKE '%$prov%' AND
lookup REGEXP 'ca|com|org|net' AND
lookup NOT LIKE '%.arpa' AND
lookup NOT LIKE '%domain.ca' AND 
ip NOT LIKE '192.168.2.1' AND
ip NOT LIKE '192.168.2.2' AND
ip NOT LIKE '192.168.2.3'
GROUP BY lookup
ORDER BY count DESC
LIMIT 100

I have my mysql server configured like a few high useage examples I found. The hardware is good, 4 cores, 8 gig rams.

This query takes about 180 seconds… Does anyone have some tips on making this more efficent?

  • 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-23T01:31:04+00:00Added an answer on May 23, 2026 at 1:31 am

    There are a lot of things wrong here. A LOT of things. I would look to the other answers for query options (you use a lot of LIKES, NOT LIKES, and functions….and you’re doing them on unkeyed columns…). If I were in your case, I’d redesign my entire database. It looks as though you’re using this to store DNS entries – host names to IP addresses.

    You may not have the option to redesign your database – maybe it’s a customer database or something that you don’t have control over. Maybe they have a lot of applications which depend on the current database design. However, if you can refactor your database, I would strongly suggest it.

    Here’s a basic rundown of what I’d do:

    1. Store the TLDs (top-level-domains) in a separate column as an ENUM. Make it an index, so it’s easily searchable, instead of trying to regex .com, .arpa, etc. TLDs are limited anyway, and they don’t change often, so this is a great candidate for an ENUM.

    2. Store the domain without the TLD in a regular column and a reversed column. You could index both columns, but depending on your searches, you may only need to index the reverse column. Basically, having a reverse column allows you to search for all hosts in one domain (ex. google) without having to do a fulltext search each time. MySQL can do a key search on the string “elgoog” in the reverse column. Because DNS is a hierarchy, this fits perfectly.

    3. Change the date and time columns from VARCHAR to DATE and TIME, respectively. This one’s an obvious change. No more str_to_time, str_to_date, etc. Absolutely no point in doing that.

    4. Store the IP addresses differently. There’s no reason to use a VARCHAR here – it’s inefficient and doesn’t make sense. Instead, use four separate columns for each octet (this is safe because all IPv4 addresses have four octets, no more, no less) as unsigned TINYINT values. This will give you 0-255, the range you need. (Each IP octet is actually 8 bits, anyway.) This should make searches much faster, especially if you key the columns.

      ex: select * from table where octet1 != 10; (this would filter out all 10.0.0.0/8 private IP space)

    The basic problem here is that your database design is flawed – and your query is using columns that aren’t indexed, and your queries are inefficient.

    If you’re stuck with the current design….I’m not sure if I can really help you. I’m sorry.

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

Sidebar

Related Questions

I need some help from the shell-script gurus out there. I have a .txt
I need some information about localization. I am using .net 2.0 with C# 2.0
All - I need some help designing a table for a Postgre SQL database.
i have a input tag which is non editable, but some times i need
I have a 'users' table with two columns, 'email' and 'new_email'. I need: A
I need some advice as to how I easily can separate test runs for
I need some info on how to use margins and how exactly padding works.
I need some software to explore and modify some SQLite databases. Does anything similar
We need some input on what is a good design pattern on using AJAX
I need some sort of interactive chart control for my .NET-based web app. I

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.