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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:41:34+00:00 2026-05-23T19:41:34+00:00

Consider the following table and its indexes: CREATE TABLE ‘Interaction’ ( ‘oid’ bigint(20) NOT

  • 0

Consider the following table and its indexes:

CREATE TABLE 'Interaction' (
  'oid' bigint(20) NOT NULL,
  'archieved' datetime DEFAULT NULL,
  'content' longtext COLLATE utf8_bin,
  'contentSentiment' int(11) DEFAULT NULL,
  'createdAt' datetime DEFAULT NULL,
  'id' varchar(255) COLLATE utf8_bin DEFAULT NULL,
  'interactionSource' longtext COLLATE utf8_bin,
  'link' varchar(255) COLLATE utf8_bin DEFAULT NULL,
  'source' varchar(255) COLLATE utf8_bin DEFAULT NULL,
  'title' varchar(255) COLLATE utf8_bin DEFAULT NULL,
  'type' int(11) DEFAULT NULL,
  'authorKloutScore' int(11) DEFAULT NULL,
  PRIMARY KEY ('oid'),
  KEY 'createdAt' ('createdAt'),
  KEY 'fullMonitorFeedSearch' ('criteria_oid','createdAt','authorKloutScore','archieved','type')
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin

Why is the following query slow to run if there is an index (fullMonitorFeedSearch) which covers it? BTW, if the ‘interactio0_.TYPE = 2’ is removed, the sql runs in 0.01 secs.

SELECT interactio0_.oid 
FROM   Interaction interactio0_ 
WHERE  interactio0_.criteria_oid = 21751021
    AND interactio0_.createdat = 10
    AND interactio0_.archieved IS NULL
    AND interactio0_.TYPE = 2
ORDER  BY interactio0_.createdat DESC 

This is the explain for the sql:

+----+-------------+--------------+-------+--------------------------------------------------------------------------+-----------------------+---------+------+---------+-------------+
| id | select_type | table        | type  | possible_keys                                                            | key                   | key_len | ref  | rows    | Extra       |
+----+-------------+--------------+-------+--------------------------------------------------------------------------+-----------------------+---------+------+---------+-------------+
|  1 | SIMPLE      | interactio0_ | range | FKD15475F24AA96F7,createdAt,fullMonitorFeedSearch                        | fullMonitorFeedSearch | 18      | NULL | 2323027 | Using where |
+----+-------------+--------------+-------+--------------------------------------------------------------------------+-----------------------+---------+------+---------+-------------+
  • 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-23T19:41:35+00:00Added an answer on May 23, 2026 at 7:41 pm

    It seems MySQL might not be able to fully use the index because the columns in the index are different from the columns used in the WHERE and also not in the same order. Try removing the column authorKloutScore from the index:

    fullMonitorFeedSearch (criteria_oid, type, createdAt, archieved)

    Then modify the query as:

    SELECT interactio0_.oid
    FROM   Interaction interactio0_
    WHERE  interactio0_.criteria_oid = 21751021
        AND interactio0_.type = 2
        AND interactio0_.createdat = 10
        AND interactio0_.archieved IS NULL
    ORDER BY interactio0_.createdat DESC;
    

    A few additional suggestions/concerns:

    1. If the type column is supposed to contain values like 1, 2, 3…, I think it makes sense to re-declare it as TINYINT UNSIGNED. That should allow you to store values in the range of 0 to 255.

    2. Similar suggestion for authorKloutScore and contentSentiment columns to re-declare as TINYINT UNSIGNED or SMALLINT UNSIGNED depending on what values the column might contain.

    3. The index and the query mentions a column criteria_oid but the column is missing from the table definition. I’m not sure if it is a typo or the column doesn’t exist.

    4. The createdAt column is DATETIME but the corresponding WHERE predicate in the query doesn’t make much sense – interactio0_.createdat = 10. Shouldn’t it be a date or date-time value in the right side. Or is it that the column is intended to store only specific data (day, month or hour)?

    5. One particular condition in the query reads interactio0_.criteria_oid = 21751021. As I had mentioned above, the column is missing in the table definition. However, the idea here is that if that column is UNIQUE, it makes more sense to remove all other WHERE conditions – select the record where criteria_oid = 21751021 and do the other checks in the resultset in PHP. However, if the column is not UNIQUE and there could be many rows with the same creative_oid, then the query is just fine.

    Hope the above helps!

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

Sidebar

Related Questions

Consider the following table: CREATE TABLE `prize` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `prize_details_id`
Consider the following SQL: CREATE TABLE USER1 ( pkUSER1_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
Consider a link table with the following columns: PersonID int NOT NULL LocationID int
Consider the following table: create table temp ( name int, a int, b int
Consider the following table which has the fields - id (int) and date_created (datetime):
Please consider the following SQL Server table and stored procedure. create table customers(cusnum int,
Consider the following Transact sql. DECLARE @table TABLE(val VARCHAR(255) NULL) INSERT INTO @table (val)
Consider the following table: Song ---- SongID GUID Primary Key Name Varchar dateAdded DateTime
Consider following MySQL table: CREATE TABLE `log` ( `what` enum('add', 'edit', 'remove') CHARACTER SET
Consider the following JavaScript code, meant to create an 8x8 table inside of a

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.