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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:05:42+00:00 2026-05-18T20:05:42+00:00

I still have following problem EXPLAIN EXTENDED SELECT `item`.`id`, `item`.`timestamp`, `item`.`label` FROM item WHERE

  • 0

I still have following problem

EXPLAIN EXTENDED SELECT
  `item`.`id`,
  `item`.`timestamp`,
  `item`.`label`
  FROM
  item
WHERE
  item.dataTypeId=30
GROUP BY
  item.id
ORDER BY
  item.timestamp DESC
LIMIT 0,6;

Id & timestamp is a primary key pair (mediumint+datetime)
dataTypeId is a foreign key (mediumint)
table is created as InnoDb

There can be more records with same id and different timestamp (versions of same item). This is the reason for group by.

I read for example this one: similar topic on stackoverflow

but it didnt solve my problem.

I’ve tried to create following indexes:

  1. index on (dataTypeId, id, timestamp) – in that order
  2. index on (dataTypeId, timestamp) – in that order
  3. index on id
  4. index on timestamp

the last two is a little piece of desperation

i think i must miss something basic –
but really do no know what.
Do not expect the solution (it would be nice 🙂 just kick me the right way 🙂

sort_buffer_size is now 4194288

edit:
explain – no indexes

"1" "SIMPLE"    "item"  "ref"   "FK_dataTypeId" "FK_dataTypeId" "4" "const" "5608"  "Using where; Using temporary; Using filesort"

explain with indexes created

"1" "SIMPLE"    "item"  "ref"   "FK_udssDataItem_1,testIndexType,testIndexTypeTimestamp,testIndexTypeIdTime"    "FK_udssDataItem_1" "4" "const" "5632"  "Using where; Using temporary; Using filesort"
  • 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-18T20:05:42+00:00Added an answer on May 18, 2026 at 8:05 pm

    There is an issue with your query. When you do the “group by id”, you may have different timestamps for the same id and have not specified which one to use (Min(), max() etc) a similar problem occurs with the “label” field.

    http://dev.mysql.com/tech-resources/articles/debunking-group-by-myths.html

    So you need agregate functions on timestamp and label otherwise the values returned may be unpredictable.

    As you are grouping by id and the sorting by timestamp, so MySQL extracts one timestamp per group so an index doesn’t really help much. You may not be able to get rid of the filesort with this query.

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

Sidebar

Related Questions

I still have following problem EXPLAIN EXTENDED SELECT `item`.`id`, `item`.`timestamp`, `item`.`label` FROM item WHERE
I have the following MySQL query: SELECT Project.*, `trk_deleted`, `trk_status`, `trk_state` FROM `project` AS
I have the following mysql query select points_for_user from items where user_id = '38415';
I have seen the following question but I still have a few doubts. Sending
In the following code how can I still have the second and third statement
Following this question and answer , I still have a bit trouble in the
I have the following code and I am still unable to get Hibernate to
I have the following statement. var search = PredicateBuilder.True<SomeType>(); search.And(f => false); // Still
I have been repeatedly asked the following questions in many interviews.... But still can't
I still have the problem and i don't know how to fix it. thanks

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.