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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:00:53+00:00 2026-05-27T13:00:53+00:00

I have two queries that are basically the same: OLD TRANSACTIONS QUERY SELECT t.payment_method,

  • 0

I have two queries that are basically the same:

OLD “TRANSACTIONS” QUERY

SELECT t.payment_method, t.amount, t.commission
FROM `transactions` t, `member_to_group` mtg, `member` m
WHERE mtg.`group_id`='37'
   AND t.`is_deleted`='No'
   AND t.`member_id`=mtg.`member_id`
   AND m.member_id=mtg.member_id
   AND m.`is_root`='No'
   AND t.`type` IN ('Payment','Credit')

NEW “PAYMENTS” QUERY

SELECT p.method, p.amount, p.commission
FROM `payments` p, `member_to_group` mtg, `member` m
WHERE mtg.`group_id`='37'
   AND p.`status`='Active'
   AND p.`member_id`=mtg.`member_id`
   AND m.member_id=mtg.member_id
   AND m.`is_root`='No'

The first from the “transactions” table, and the second from a newer table called “payments”. Basically we had one giant table for every transaction (payments, credits, charges, fees,etc) and it got out of hand because there were always a great deal of fields that weren’t used for each type — so we split the basic types up.

For some reason, despite the better organization of the newer table system (all in the same database, mind you), and the similarities between the queries, the older “transaction” query runs much faster. The “transaction” table returns the result in 0.004 seconds while the “payments” query takes 0.303. In some areas on the web application (e.g. listings for multiple groups), this translates into 40 second page load times (as opposed to under 3).

Is there a single field (or multi-field) index I might want to use? Can I further optimize the new query?

This is running on MySQL 5.0.92

EDIT 1: I currently have single-field indexes on “transactions” (transaction_id, member_id) and “payments” (id, member_id). Unfortunately I only have access to PHPMYADMIN on this particular server and the EXPLAIN output isn’t readily copyable. That said, I can see a difference on the “transaction” query in that it says “using where;using index” on the mtg table whereas the “payment” transaction simply says “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-27T13:00:54+00:00Added an answer on May 27, 2026 at 1:00 pm

    First of all i would rewrite it as :

    SELECT 
        payments.method, 
        payments.amount,
        payments.commission
    FROM payments
        LEFT JOIN member_to_group ON payments.member_id = member_to_group.member_id 
        LEFT JOIN member ON member.member_id = member_to_group.member_id
    WHERE member_to_group.group_id = '37'
        AND payments.status = 'Active'
        AND member.is_root = 'No'
    

    Then, try to compare the both queries using EXPLAIN statement. This should show you where are the differences.

    Next i would take a look at this line WHERE member_to_group.group_id = '37' and make sure that i compare the columns against INT value instead of VARCHAR .. with all the fitting indexes.

    As for payments.status and member.is_root , both columns should be indexed (AFAIK, MySQL still does not support partial indexing).

    I am assuming that that following columns are primary/foreign keys and indexed accordingly:

    • payments.member_id
    • member_to_group.member_id
    • member.member_id

    P.S. you could play around with order of WHERE statements , but i think that should be already handled by database’s internal query optimization .. but who knows , it’s mysql.


    update

    If the EXPLAIN says that you are not using indexes on member_to_group table, then you should check the indexes that both columns ( which are used in that query ): group_id and member_id .. at least one of them is not indexed in member_to_group.

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

Sidebar

Related Questions

I have a query to select from another sub-query select. While the two queries
I have two queries that I run in the same table: SELECT id, COUNT(up)
I have two queries, as following: SELECT SQL_CALC_FOUND_ROWS Id, Name FROM my_table WHERE Name
I have two mysql queries: $sql = SELECT * FROM content WHERE threadName LIKE
I have the following two queries: select count(*) from segmentation_cycle_recipients scr , segmentation_instance si
I have two queries that produce the same output. One is using the Intersect
I have two SQL queries that I'm running from a C# winform, and I
Given: Two queries that require filtering: select top 2 t1.ID, t1.ReceivedDate from Table t1
I have two queries. The first query looks like this : SELECT subject_id, period,
I have two queries that I thought meant the same thing, but I keep

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.