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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:56:43+00:00 2026-05-20T12:56:43+00:00

I have a database that stores products. The two biggest tables are my products

  • 0

I have a database that stores products. The two biggest tables are my products table and images table.
Products: ~19.000 rows

Images: ~34.000 rows

Categories: ~60 rows

Raw categories: ~1200 rows

Brands: 700 rows

(The other tables are only a couple of rows)

I also have a table with brands, raw categories, static categories (the raw categories are mapped to a static category).

I have created a Product VIEW to gather the data I need, like this:

CREATE OR REPLACE VIEW `jos_clothes_view_products` AS
SELECT tbl.*, r.name AS reseller, b.name AS brand, rcat.raw_name AS cats_raw, cats1.name AS cat1, cats1.slug AS catslug1, cats2.name AS cat2, cats2.slug AS catslug2
FROM `jos_clothes_products` AS tbl
LEFT JOIN `jos_clothes_brands` AS b ON b.clothes_brand_id = tbl.clothes_brand_id
LEFT JOIN `jos_clothes_resellers` AS r ON r.clothes_reseller_id = tbl.clothes_reseller_id
LEFT JOIN `jos_clothes_catraws` AS rcat ON rcat.clothes_catraw_id = tbl.clothes_catraw_id
LEFT JOIN `jos_clothes_categories` AS cats2 ON cats2.clothes_category_id = rcat.clothes_category_id
LEFT JOIN `jos_clothes_categories` AS cats1 ON cats1.clothes_category_id = cats2.parent_id

Then when running a query like this from PHP:

SELECT `tbl`.* FROM `jos_clothes_view_products` AS `tbl` WHERE  `tbl`.`cat1` != 'NULL' AND `tbl`.`enabled` = '1' ORDER BY `created_on` DESC , `ordering` ASC LIMIT 0 , 20;

The query is often very slow! Not always though (probably because of caching?). I have also noticed that it creates a tmp-table at about 200MB in size. Sometimes it gets even bigger and fails with “Invalid key for file….”.

Any ideas how I can optimize the query? Or the VIEW actually, I guess it’s the bottleneck here. Correct?

Product table structure:

CREATE TABLE IF NOT EXISTS `jos_clothes_products` (
  `clothes_product_id` bigint(20) unsigned NOT NULL auto_increment,
  `clothes_reseller_id` bigint(20) unsigned NOT NULL,
  `aff_prod_id` varchar(50) NOT NULL,
  `title` varchar(255) NOT NULL,
  `description` text NOT NULL,
  `gender` varchar(20) NOT NULL,
  `clothes_brand_id` bigint(20) unsigned NOT NULL,
  `color` varchar(255) NOT NULL,
  `size` varchar(50) NOT NULL,
  `clothes_catraw_id` bigint(20) unsigned NOT NULL,
  `price` decimal(10,2) NOT NULL default '0.00',
  `shipping_cost` varchar(20) NOT NULL default '0.00',
  `currency` varchar(10) NOT NULL,
  `availibility` tinyint(1) NOT NULL,
  `product_url` varchar(350) NOT NULL,
  `real_url` varchar(300) NOT NULL,
  `slug` varchar(255) NOT NULL,
  `hits` int(11) NOT NULL,
  `enabled` tinyint(1) NOT NULL default '0',
  `access` int(11) NOT NULL default '0',
  `ordering` bigint(20) unsigned NOT NULL,
  `created_on` datetime NOT NULL default '0000-00-00 00:00:00',
  `created_by` int(11) NOT NULL default '0',
  `modified_on` datetime NOT NULL default '0000-00-00 00:00:00',
  `modified_by` int(11) NOT NULL default '0',
  `locked_on` datetime NOT NULL default '0000-00-00 00:00:00',
  `locked_by` int(11) NOT NULL default '0',
  PRIMARY KEY  (`clothes_product_id`),
  KEY `clothes_brand_id` (`clothes_brand_id`),
  KEY `clothes_catraw_id` (`clothes_catraw_id`),
  KEY `created_on` (`created_on`),
  KEY `clothes_reseller_id` (`clothes_reseller_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=18962 ;

Any ideas?

Best Regards

EDIT: Structure of jos_clothes_catraws

--
-- Struktur för tabell `jos_clothes_catraws`
--

CREATE TABLE IF NOT EXISTS `jos_clothes_catraws` (
  `clothes_catraw_id` int(11) unsigned NOT NULL auto_increment,
  `clothes_category_id` int(11) unsigned NOT NULL default '0',
  `clothes_reseller_id` int(11) unsigned NOT NULL,
  `raw_name` varchar(255) NOT NULL,
  PRIMARY KEY  (`clothes_catraw_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1289 ;
  • 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-20T12:56:44+00:00Added an answer on May 20, 2026 at 12:56 pm

    Looking at your EXPLAIN output, it looks like the culprit is the jos_clothes_catraws table which is not using any indexes to do the join. This is the one generating the large temp table. First check whether the table has a key for clothes_catraw_id.

    You could also use USE INDEX syntax to force the use of the index or do an ANALYZE TABLE on the table to make sure that the table statistics are updated so that the temp table is avoided.

    Another point that I can see is the mix of ascending and descending order in the query you use in PHP. Try using a descending order key for the created_on field and preferably a combined key for the two fields.

    Also try running the query directly instead of through the view as there are mentions in the MySQL Restrictions on Views section that some views may not use indexes although the actual statement could use the indexes.

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

Sidebar

Related Questions

I have a database that has a table email_eml that stores 3 attributes name_eml,
Ok I have a table in my SQL Server database that stores comments. My
I have an application that stores images in a database. Now I have learned
I have to design a database that stores products with variable number of properties,
I have a database that stores products available on the market and products still
I have a database table which stores products. Each product can have multiple colours.
I have a database table that Stores Maximum and Minimum Price Breaks for a
I have a database that stores dates broken into int's. I.e. Day, Month and
I have a MySql database that stores a timestamp for each record I insert.
Our scenario: We have a main database that stores company-wide information. We have several

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.