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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:13:19+00:00 2026-05-11T10:13:19+00:00

As a more general case of this question because I think it may be

  • 0

As a more general case of this question because I think it may be of interest to more people…What’s the best way to perform a fulltext search on two tables? Assume there are three tables, one for programs (with submitter_id) and one each for tags and descriptions with object_id: foreign keys referring to records in programs. We want the submitter_id of programs with certain text in their tags OR descriptions. We have to use MATCH AGAINST for reasons that I won’t go into here. Don’t get hung up on that aspect.

programs   id   submitter_id tags_programs   object_id   text descriptions_programs   object_id   text 

The following works and executes in a 20ms or so:

SELECT p.submitter_id FROM programs p WHERE p.id IN     (SELECT t.object_id     FROM titles_programs t     WHERE MATCH (t.text) AGAINST ('china') UNION ALL     SELECT d.object_id     FROM descriptions_programs d     WHERE MATCH (d.text) AGAINST ('china')) 

but I tried to rewrite this as a JOIN as follows and it runs for a very long time. I have to kill it after 60 seconds.

SELECT p.id  FROM descriptions_programs d, tags_programs t, programs p WHERE (d.object_id=p.id AND MATCH (d.text) AGAINST ('china')) OR    (t.object_id=p.id AND MATCH (t.text) AGAINST ('china')) 

Just out of curiosity I replaced the OR with AND. That also runs in s few milliseconds, but it’s not what I need. What’s wrong with the above second query? I can live with the UNION and subselects, but I’d like to understand.

  • 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. 2026-05-11T10:13:20+00:00Added an answer on May 11, 2026 at 10:13 am

    Join after the filters (e.g. join the results), don’t try to join and then filter.

    The reason is that you lose use of your fulltext index.

    Clarification in response to the comment: I’m using the word join generically here, not as JOIN but as a synonym for merge or combine.

    I’m essentially saying you should use the first (faster) query, or something like it. The reason it’s faster is that each of the subqueries is sufficiently uncluttered that the db can use that table’s full text index to do the select very quickly. Joining the two (presumably much smaller) result sets (with UNION) is also fast. This means the whole thing is fast.

    The slow version winds up walking through lots of data testing it to see if it’s what you want, rather than quickly winnowing the data down and only searching through rows you are likely to actually want.

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

Sidebar

Related Questions

This is more a general question but my particular case involves a ruby/rails app
this may be a more general opengl question. using OpenGL ES for 2d, and
This is more like general question: Is there a way to assign a value
I suppose this question is more general than working with COM components. I have
I have a Yesod application (but question is more general than this) that allows
I know this SO question, but it deals with the subject in more general
This is more of a general design question I guess... I have an Ajax
So, I've come back to ask, once more, a patterns-related question. This may be
Be forewarned: This question seems way more obvious than it actually is. I'd like
My question is not about a specific code snippet but more general, so please

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.