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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:55:30+00:00 2026-05-24T09:55:30+00:00

I am trying to optimise my site and would be grateful for some help.

  • 0

I am trying to optimise my site and would be grateful for some help.

The site is a mobile phone comparison site and the query is to show the offers for a particular phone. The data is on 2 tables, the cmp_deals table has 931000 entries and the cmp_tariffs table has 2600 entries. The common field is the tariff_id.

###The deals table###
id  int(11)
hs_id   varchar(30)
tariff_id   varchar(30)
hs_price    decimal(4,2)
months_free     int(2)
months_half     int(2)
cash_back   decimal(4,2)
free_gift   text
retailer_id     varchar(20)

###Deals Indexes###
hs_id   INDEX   430     Edit    Drop    hs_id
months_half     INDEX   33      Edit    Drop    months_half
months_free     INDEX   25      Edit    Drop    months_free
hs_price    INDEX   2223    Edit    Drop    hs_price
cash_back   INDEX<br/>


###The tariff table###
ID  int(11)
tariff_id   varchar(30)
tariff_name     varchar(255)
tariff_desc     text
anytime_mins    int(5)
offpeak_mins    int(5)
texts   int(5)
line_rental     decimal(4,2)
cost_offset     decimal(4,2)

No Indexes

The initial query is

SELECT * FROM `cmp_deals`
LEFT JOIN `cmp_tariffs` USING (tariff_id)
WHERE hs_id = 'iphone432gbwhite'

and then the results can be sorted by various items in the cmp_deals table such as cash_back or free_gift

SELECT * FROM `cmp_deals`
LEFT JOIN `cmp_tariffs` USING (tariff_id)
WHERE hs_id = 'iphone432gbwhite'
ORDER BY hs_price DESC
LIMIT 30

This is the result when I run an “EXPLAIN” command, but I don’t really understand the results.

id  select_type     table   type    possible_keys   key     key_len     ref     rows    Extra<br/>
1   SIMPLE  cmp_deals   ref     hs_id   hs_id   92  const   179     Using where; Using temporary; Using filesort<br/>
1   SIMPLE  cmp_tariffs     ALL     NULL    NULL    NULL    NULL    2582

I would like to know please if I am doing these queries in the most efficient way as the queries are averaging at 2 seconds plus.

Thanks in advance

  • 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-24T09:55:30+00:00Added an answer on May 24, 2026 at 9:55 am

    Can’t say I’m a fan of all those double IDs (numeric and human-readable). If you don’t actually need the varchar versions, drop them.

    Change the foreign key cmp_deals.tarrif_id to reference cmp_tarrifs.ID (ie, make it an INT and if using InnoDB, actually create foreign key constraints).

    At the very least make cmp_tariffs.ID a primary key and optionally cmp_tariffs.tariff_id a unique index.

    Having zero indexes on the tariffs table means it has to do a table scan to complete the join.

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

Sidebar

Related Questions

I'm trying to optimise a complex query in PostgreSQL 9.1.2, which calls some functions.
I'm looking at trying to optimise a particular function in a PHP application and
Recently, I was trying to optimise this query UPDATE Analytics SET UserID = x.UserID
I'm trying to optimise the performance of a string comparison operation on each string
I'm trying to optimise my query, it has an inner join and coalesce. The
I'm still trying to figure out a way to get a mobile site running.
I'm trying to optimize a report query run on an ecommerce site. I'm pretty
I'm trying to optimise my query. Basically I have an Department table and a
I'm trying to optimise a query for a SQLServerCE database running on a Windows
I am trying to optimize some stored procedures on a SQL Server 2000 database

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.