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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:37:39+00:00 2026-06-12T14:37:39+00:00

Given i have articles which are tagged, one article can have n tags. Currently

  • 0

Given i have articles which are tagged, one article can have n tags.
Currently there are around 250k tag-entries which all point back
onto their belonging article.

Now i want to find all tags from articles matching certain criteria.
I came up with two different approaches. Both which have drawbacks and are slow.
May be someone can point me in the right direction on how to speed them up or even come
up with a better solution.

Keys (ind,rindex) are varchar(255) unfortunately this cant be changed

Query #1

taking 7.5 – subselect returns 60 records in 50ms

SELECT count(*) AS tagscount, tags.value FROM tags 
  WHERE tags.`rindex` IN 
  ( 
    SELECT article.ind 
       FROM article 
       INNER JOIN struktur ON (struktur.ind = article.struktur) 
    WHERE article.date = '2011-12-21'
  ) 
  AND tags.`rtable` = 'article'
  GROUP BY tags.value ORDER BY tagscount DESC LIMIT 20

Query #2

taking 60ms

SELECT count(*) AS tagscount, tags.value FROM tags 
  INNER JOIN article ON (article.ind = tags.rindex AND tags.rtable = 'article')
  LEFT JOIN structure ON (article.structure = structure.ind)
WHERE article.date = '2011-12-21'
GROUP BY tags.value ORDER BY tagscount DESC LIMIT 20 

The Strange Part – Important

When i change article.date = '2011-12-21' into article.date >= '2009-12-21'
Query #1

  • taking 10.1s – subselect returns 18k rows in 70ms

Query #2

  • taking 14.2s

If you need further information i’ll be happy to provide

SCHEMAS

mysql> SHOW COLUMNS FROM tags;
+---------+--------------+------+-----+---------+-------+
| Field   | Type         | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| ind     | varchar(255) | NO   | PRI |         |       |
| rtable  | varchar(255) | NO   | MUL |         |       |
| rindex  | varchar(255) | NO   | MUL |         |       |
| value   | varchar(40)  | YES  | MUL | NULL    |       |
+---------+--------------+------+-----+---------+-------+

mysql> SHOW indexes FROM tags
+-------+------------+---------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name            | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+-------+------------+---------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| tags  |          0 | tags_ind            |            1 | ind         | A         |      275834 |     NULL | NULL   |      | BTREE      |         |
| tags  |          1 | tags_tag            |            1 | tag         | A         |       27583 |     NULL | NULL   | YES  | BTREE      |         |
| tags  |          1 | tags_rindex         |            1 | rindex      | A         |       55166 |     NULL | NULL   |      | BTREE      |         |
| tags  |          1 | tags_rindex_tabelle |            1 | tabelle     | A         |           4 |       30 | NULL   |      | BTREE      |         |
| tags  |          1 | tags_rindex_tabelle |            2 | rindex      | A         |       55166 |       50 | NULL   |      | BTREE      |         |
+-------+------------+---------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+

mysql> SHOW COLUMNS FROM structure;
+------------------------+--------------+------+-----+---------+-------+
| Field                  | Type         | Null | Key | Default | Extra |
+------------------------+--------------+------+-----+---------+-------+
| ind                    | varchar(255) | NO   | PRI |         |       |
+------------------------+--------------+------+-----+---------+-------+

mysql> SHOW COLUMNS FROM artikel;
+--------------------+--------------+------+-----+------------+-------+
| Field              | Type         | Null | Key | Default    | Extra |
+--------------------+--------------+------+-----+------------+-------+
| ind                | varchar(255) | NO   | PRI |            |       |
| date               | date         | NO   | MUL | 0000-00-00 |       |
+--------------------+--------------+------+-----+------------+-------+

EXPLAIN

mysql> explain #1
+----+--------------------+----------+--------+-------------------------------------------------------------------------------------+---------------------+---------+---------------------+--------+----------------------------------------------+
| id | select_type        | table    | type   | possible_keys                                                                       | key                 | key_len | ref                 | rows   | Extra                                        |
+----+--------------------+----------+--------+-------------------------------------------------------------------------------------+---------------------+---------+---------------------+--------+----------------------------------------------+
|  1 | PRIMARY            | tags     | ref    | tags_rindex_tabelle                                                                 | tags_rindex_tabelle | 32      | const               | 177175 | Using where; Using temporary; Using filesort |
|  2 | DEPENDENT SUBQUERY | artikel  | eq_ref | artikel_ind,zeitraum_start_i,freigabe_i,korrektur_i,struktur_i,artikel_start_slot_i | artikel_ind         | 257     | func                |      1 | Using where                                  |
|  2 | DEPENDENT SUBQUERY | struktur | eq_ref | struktur_ind,struktur_host                                                          | struktur_ind        | 257     | ec.artikel.struktur |      1 | Using where                                  |
+----+--------------------+----------+--------+-------------------------------------------------------------------------------------+---------------------+---------+---------------------+--------+----------------------------------------------+
mysql> explain #2
+----+-------------+----------+--------+-------------------------------------------------------------------------------------+---------------------+---------+---------------------+--------+----------------------------------------------+
| id | select_type | table    | type   | possible_keys                                                                       | key                 | key_len | ref                 | rows   | Extra                                        |
+----+-------------+----------+--------+-------------------------------------------------------------------------------------+---------------------+---------+---------------------+--------+----------------------------------------------+
|  1 | SIMPLE      | tags     | ref    | tags_rindex,tags_rindex_tabelle                                                     | tags_rindex_tabelle | 32      | const               | 177175 | Using where; Using temporary; Using filesort |
|  1 | SIMPLE      | artikel  | eq_ref | artikel_ind,zeitraum_start_i,freigabe_i,korrektur_i,struktur_i,artikel_start_slot_i | artikel_ind         | 257     | ec.tags.rindex      |      1 | Using where                                  |
|  1 | SIMPLE      | struktur | eq_ref | struktur_ind,struktur_host                                                          | struktur_ind        | 257     | ec.artikel.struktur |      1 | 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-06-12T14:37:41+00:00Added an answer on June 12, 2026 at 2:37 pm

    I assume artikel.ind is not restricted to being ascending lexical order in the same order as artikel.date. If it is, the obvious solution would be to add a restriction to the rindex which corresponded to the date range.

    As it is, it looks like an appropriate plan is being used.

    Your best bet without changing data types would be to create a materialized view indexed on (artikel.date, tags.value, artikel.ind) and then query that.

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

Sidebar

Related Questions

I have a warehouse in which I keep goods. Each article occupies given volume
Given I have an integer value of, e.g., 10 . How can I create
Given I have table with some data... I have a query which is used
Given I have two File objects I can think of the following implementation: public
Given i have the IO function: // this can either be IO or some
I came across a few articles like this one , which suggest that some
I have seen this question before and found this example in http://www.zeitoun.net/articles/comet_and_php/start which is
Let us suppose I have an app which has articles and authors. It persists
I would like to count the number of tags given a specific article. I've
I have an application that is currently running on IIS 6.0 with one worker

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.