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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:05:30+00:00 2026-05-16T21:05:30+00:00

I’m working on a personal project focusing on analysis of text in a database.

  • 0

I’m working on a personal project focusing on analysis of text in a database. My intent is to do something interesting and learn about SQL and sqlite. So with my novice abilities in mind, I’d like to get advice on doing this more efficiently.

Say, for example, I want to pick out the types of food in an article A. I parse my article, and if I find a food F, then I add F to table items. Then I add A.id and F.id to results. When I parse my article and find a food G that already exists in items, all I do is add A.id and G.id to results.

So my schemas look something like the following:

  • articles: id, article
  • results: id, item_id, article_id
  • items: id, foodtype, food

If I want to find all the articles that talk about oranges and grapes and any vegetable, then I’d start with something like this:

SELECT * 
  FROM articles 
INNER JOIN results ON articles.id = results.article_id  
INNER JOIN items ON results.item_id = items.id

and add:

WHERE foodtype='vegetable' OR food='orange' OR food='grape'

In reality, my database is much bigger. There are thousands of articles and over a hundred thousand extracted “foods.” Most of these queries in which I join 3 tables don’t return, even if I limit things to 100 results. I’ve tried creating an index on fields that are commonly in my WHERE clauses, like food and foodtype, but have seen no improvement.

Are there improvements that I can make to my database or query?

  • 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-16T21:05:30+00:00Added an answer on May 16, 2026 at 9:05 pm

    Retrieve Only The Columns You Need

    The first problem with the query is that SELECT * is returning all columns from all tables joined in the query. That means the values in the JOIN criteria, on both sides of the evaluation, are being returned. It’s better to write out the actual columns you need, because all three you listed have an id column–which complicates correct value retrieval unless using ordinal position (not a good practice–change position, data retrieval isn’t what it should be).

    Using table aliases minimizes what you need to use to reference a specific table:

    SELECT a.article 
      FROM ARTICLES a
      JOIN RESULTS r ON r.article_id = a.id
      JOIN ITEMS i ON i.id = r.item_id
    

    Indexing

    Indexing the foreign keys–what you are using to for JOIN criteria, should be the second thing on the list after the primary key for the table.

    Then you have to periodically run the ANALYZE command because the statistics are…

    …not automatically updated as the content of the database changes. If the content of the database changes significantly, or if the database schema changes, then one should consider rerunning the ANALYZE command in order to update the statistics.

    These statistics are what the optimizer uses for it’s query decision, along with the presence of indexes.

    ORs Are Notoriously Bad for Performance

    You might try re-writing the query so it doesn’t use ORs with a UNION:

    SELECT a.article 
      FROM ARTICLES a
      JOIN RESULTS r ON r.article_id = a.id
      JOIN ITEMS i ON i.id = r.item_id
     WHERE i.foodtype = 'vegetable'
    UNION 
    SELECT a.article 
      FROM ARTICLES a
      JOIN RESULTS r ON r.article_id = a.id
      JOIN ITEMS i ON i.id = r.item_id
     WHERE i.food IN ('orange', 'grape')
    

    Be aware that UNION is slower than UNION ALL, because UNION removes duplicates. UNION ALL is faster because it doesn’t remove duplicates.

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

Sidebar

Related Questions

I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a view passing on information from a database: def serve_article(request, id): served_article

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.