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

  • Home
  • SEARCH
  • 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 8074643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:43:26+00:00 2026-06-05T14:43:26+00:00

When I first made this query and the table was relatively small, it ran

  • 0

When I first made this query and the table was relatively small, it ran very quickly, but over time as the update table size increased (now about 6000 rows) the query has been extrememly slow and resource intensive. The server I’m using is the 1GB RAM VPS from linode.com, and I haven’t actually waited long enough for the query to finish.

Interestingly, without the extra condition in the left join (SELECT MAX(u2.time)) it runs in < 0.5s.

I had a look in the process list of mySQL while the query was running, and it showed as ‘Sending Data’ for the whole time

Here’s the query:

SELECT 
  s.ID as sid, s.country AS country, 
  s.name AS name, s.ip AS ip, 
  u.connPlayers AS cp, u.maxPlayers AS mp
FROM servers AS s 

LEFT JOIN updates AS u 
  ON u.serverID = s.ID 
  AND u.time = 
      (SELECT MAX(u2.time) 
         FROM updates AS u2 
         WHERE u2.serverID = s.ID) 
ORDER BY RAND(MINUTE(NOW())) 
LIMIT 0,10

And here’s the my.cnf file: http://redream.co.nz/my.cnf

Table structure:

Servers table (20 rows
)

Field   Type
ID      int(10) Unique Key           
ip      varchar(200)                 
country varchar(2)               
name    varchar(600)             
motd    varchar(600)                 
desc    mediumtext               
version varchar(600)    

Update table (6000 rows)

Field       Type
serverID    int(10)              
ping        int(10)              
time        int(14)              
uptime      int(10)              
connPlayers int(10)              
maxPlayers  int(10)              
uptime      int(14)
  • 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-06-05T14:43:28+00:00Added an answer on June 5, 2026 at 2:43 pm

    I am no MySQL expert, but I think this will work for MySQL:

    SELECT 
      s.ID as sid, s.country AS country, 
      s.name AS name, s.ip AS ip, 
      u.connPlayers AS cp, u.maxPlayers AS mp
    FROM servers AS s 
    
    LEFT JOIN (
        SELECT u.serverId, u.connPlayers, u.maxPlayers
        FROM updates u
        INNER JOIN (SELECT serverId, max(time) AS 'maxTime' FROM updates GROUP BY serverId) AS u2
            ON u.serverId = u2.serverId AND u.time = u2.maxTime 
    ) AS u ON u.serverID = s.ID 
    
    ORDER BY RAND(MINUTE(NOW())) 
    LIMIT 0,10
    

    The important change is that the left join now contains the following subquery:

    SELECT u.serverId, u.connPlayers, u.maxPlayers
    FROM updates u
    INNER JOIN (SELECT serverId, max(time) AS 'maxTime' FROM updates GROUP BY serverId) AS u2
        ON u.serverId = u2.serverId AND u.time = u2.maxTime 
    

    This subquery again contains a subquery and returns for each serverId the row with the maximum time value. The above subquery is only executed once instead of for each row in the cross product.

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

Sidebar

Related Questions

This code really made me confused. The first and second time I ran it,
I had a different problem first, so I made this post: Java JPanel mouse
First of all my tree is made up of nodes that look like this:
First of all, is this possibly ready-made? Hibernate 3.6 , JDBC batch_size 500 ,
This is my first winform app in .NET... I have made a couple of
I've got the following code - this is the first time I've really attempted
I made a package which I can use like this: select * from table(my_package.my_function(99,
I just found this irregularitry in a query i made, why does the result
Running this query in sql server 2008 now, but soon plan to move it
Hi, I have made this simple script but I need to have it check

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.