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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:31:57+00:00 2026-05-22T03:31:57+00:00

I use Sphinx for fulltext search on my app. I use a view to

  • 0

I use Sphinx for fulltext search on my app. I use a view to filter the data from a products table and Sphinx indexes this view. Right now I have a hard coded field under the products table with it’s related tags, but that is not so good as tags might change and I would have to manipulate the hard coded field every time.

So I was thinking that I could create the view with GROUP_CONCAT, listing all the related tags for me with a syntax like this:

SELECT p.id AS id, GROUP_CONCAT(t.tag SEPARATOR '|') AS tags,
UNIX_TIMESTAMP(p.created) AS created
FROM products p
INNER JOIN products_tags pt ON pt.product_id = p.id
INNER JOIN tags t ON t.id = pt.tag_id
AND p.deleted = 0
AND (p.images IS NOT NULL OR p.images <> '')
AND p.status LIKE 'listed'
GROUP BY p.id;

The problem with this query is that it takes ages to run. It’s really slow. To retrieve only one record, it takes up to 5 seconds. This is the EXPLAIN output:

1, SIMPLE, pt, ALL, , , , , 165029, Using temporary; Using filesort
1, SIMPLE, p, eq_ref, PRIMARY, PRIMARY, 4, trych_default.pt.product_id, 1, Using where
1, SIMPLE, t, eq_ref, PRIMARY, PRIMARY, 4, trych_default.pt.tag_id, 1, 

I wonder if there is any way to improve the query or maybe a better solution to my problem. Thanks!

  • 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-22T03:31:58+00:00Added an answer on May 22, 2026 at 3:31 am

    You’re probably missing an index. With the following schema, this same query hit the index for every table:

    CREATE TABLE `products` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `deleted` tinyint(1) unsigned NOT NULL DEFAULT '0',
      `status` varchar(255) NOT NULL DEFAULT 'listed',
      `images` varchar(255) DEFAULT NULL,
      `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    CREATE TABLE `tags` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `tag` varchar(255) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    CREATE TABLE `products_tags` (
      `product_id` int(11) NOT NULL,
      `tag_id` int(11) NOT NULL DEFAULT '0',
      PRIMARY KEY (`product_id`,`tag_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    

    Here are the results of the EXPLAIN query:

    EXPLAIN SELECT p.id AS id, GROUP_CONCAT(t.tag SEPARATOR '|') AS tags,
    UNIX_TIMESTAMP(p.created) AS created
    FROM products p
    INNER JOIN products_tags pt ON pt.product_id = p.id
    INNER JOIN tags t ON t.id = pt.tag_id
    WHERE p.deleted = 0
    AND (p.images IS NOT NULL OR p.images <> '')
    AND p.status LIKE 'listed'
    GROUP BY p.id;
    
    +----+-------------+-------+--------+---------------+---------+---------+----------------+------+-------------+
    | id | select_type | table | type   | possible_keys | key     | key_len | ref            | rows | Extra       |
    +----+-------------+-------+--------+---------------+---------+---------+----------------+------+-------------+
    |  1 | SIMPLE      | p     | index  | PRIMARY       | PRIMARY | 4       | NULL           |    1 | Using where |
    |  1 | SIMPLE      | pt    | ref    | PRIMARY       | PRIMARY | 4       | test.p.id      |    1 | Using index |
    |  1 | SIMPLE      | t     | eq_ref | PRIMARY       | PRIMARY | 4       | test.pt.tag_id |    1 |             |
    +----+-------------+-------+--------+---------------+---------+---------+----------------+------+-------------+
    3 rows in set (0.00 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We use a data acquisition card to take readings from a device that increases
Possible Duplicate: Choosing a stand-alone full-text search server: Sphinx or SOLR? I will use
Is it possible to use Sphinx autodoc to generate documentation for my fabfile, from
I need to create a simple search but I can't afford to use Sphinx.
I think the table generated from Sphinx is not pretty, as it produces the
I'm trying to investigate sphinx rt indexes to use in future project and have
So I use sphinx search server (0.99) with Sphinx PHP PECL extension. I've configured
I use thinking sphinx in my project on refinery cms. And I received this
use this website a lot but first time posting. My program creates a number
Use case: I've just entered insert mode, and typed some text. Now I want

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.