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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:56:09+00:00 2026-05-13T13:56:09+00:00

This is the table structure: for_id from_id for_folder from_folder deleted The number 2 represents

  • 0

This is the table structure:

for_id
from_id
for_folder
from_folder
deleted

The number 2 represents my ID and this is the query:

SELECT *
FROM poruke_konverzacija
WHERE (
(
for_id =2
AND for_folder = "inbox"
)
OR (
from_id =2
AND from_folder = "inbox"
)
)
AND deleted !=2

I have near 500k records on that table and when i run explain, this is what i get:

id  select_type  table  type  possible_keys  key  key_len  ref  rows  Extra
1  SIMPLE  poruke_konverzacija  ALL  obrisano,za_id,od_id  NULL  NULL  NULL  456884  Using where; Using filesort

I have indexed for_id from_id for_folder from_folder and the query is really slow. Is there any other way to do so and get the same results ?

  • 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-13T13:56:09+00:00Added an answer on May 13, 2026 at 1:56 pm

    Index deleted also. As well…A union may be better, running two concurrent queries rather than one long one..

    Additionally indexing/selecting on string fields is always slower. If you can make a look up table for the folders

    ie

    id ----- folder
    1        inbox
    2        sent
    3        trash
    

    in your poruke_konverzacija table convert the from_folder and for_folder to the equivalent ID

    SELECT *
    FROM poruke_konverzacija
    WHERE
    for_id =2
    AND for_folder = "inbox"
    AND deleted !=2
    UNION
    SELECT *
    FROM poruke_konverzacija
    WHERE
    from_id =2
    AND from_folder = "inbox"
    AND deleted!=2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an table structure like this mysql> SELECT id, name, parent_id FROM categories;
I have this query: select distinct id,name from table1 For a given ID, the
this is my database structure for my terms table (categories): id | name |
Table structure goes something like this: Table: Purchasers Columns: id | organization | city
I have this table structure on a SQL Server 2008 R2 database: CREATE TABLE
I have this table structure and would like to map it using Fluent Hibernate
I have my Table structure like this :: ATT_Table : Fields - Act_ID, Assigned_To_ID,
I'm using Hibernate 3.3.1 and am following along in modelling this sample table structure
This is my table structure groupings id groupName 1 group1 2 group2 3 group3
I've got this really basic table structure: Posts PostXTags PostTags There is a 1-n

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.