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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:10:48+00:00 2026-05-24T11:10:48+00:00

I learned the hard way that i shouldn’t store serialized data in a table

  • 0

I learned the hard way that i shouldn’t store serialized data in a table when i need to make it searchable .

So i made 3 tables the base & two 1-n relation tables .

enter image description here

So here is the query i get if i want to select a specific activity .

SELECT
jdc_organizations_activities.id
FROM
jdc_activity_sector ,
jdc_activity_type
INNER JOIN jdc_organizations_activities ON jdc_activity_type.activityId = jdc_organizations_activities.id 
AND 
jdc_activity_sector.activityId = jdc_organizations_activities.id
WHERE
jdc_activity_sector.activitySector = 5 AND
jdc_activity_type.activityType = 3

Questions :

1- What kind of indexes can i add on a 1-n relation table , i already have a unique combination of (activityId – activitySector) & (activityId – activityType)

2- Is there a better way to write the query to have a better performance ?

Thank you !

  • 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-24T11:10:48+00:00Added an answer on May 24, 2026 at 11:10 am

    I would re-organise the query to avoid the cross product caused by using , notation.

    Also, you are effectively only using the sector and type tables as filters. So put activity table first, and then join on your other tables.

    Some may suggest that; the first join should ideally be the join which is most likely to restrict your results the most, leaving the minimal amount of work to do in the second join. In reality, the sql engine can actually re-arrange your query when generateing a plan, but it does help to think this way to help you think about the efforts the sql engine are having to go to.

    Finally, there are the indexes on each table. I would actually suggest reversing the Indexes…
    – ActivitySector THEN ActivityId
    – ActivityType THEN ActivityId

    This is specifically because the sql engine is manipulating your query. It can take the WHERE clause and say “only include records from the Sector table where ActivitySector = 5”, and similarly for the Type table. By having the Sector and Type identifies FIRST in the index, this filtering of the tables can be done much faster, and then the joins will have much less work to do.

    SELECT
      [activity].id
    FROM
      jdc_organizations_activities    AS [activity]
    INNER JOIN
      jdc_activity_sector             AS [sector]
        ON [activity].id = [sector].activityId
    INNER JOIN
      jdc_activity_type               AS [type]
        ON [activity].id = [type].activityId
    WHERE
      [sector].activitySector = 5
      AND [type].activityType = 3
    

    Or, because you don’t actually use the content of the Activity table…

    SELECT
      [sector].activityId
    FROM
      jdc_activity_sector             AS [sector]
    INNER JOIN
      jdc_activity_type               AS [type]
        ON [sector].activityId = [type].activityId
    WHERE
      [sector].activitySector = 5
      AND [type].activityType = 3
    

    Or…

    SELECT
      [activity].id
    FROM
      jdc_organizations_activities    AS [activity]
    WHERE
      EXISTS (SELECT * FROM jdc_activity_sector WHERE activityId = [activity].id AND activitySector = 5)
      AND EXISTS (SELECT * FROM jdc_activity_type WHERE activityId = [activity].id AND activityType = 3)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've learned (the hard way) that I need to add parentheses around JSON data,
I just learned (the hard way) that Java Component s can only have one
as I learned the hard way, Flash streams your .swf, that is, it can
Coming from WinForms/WPF I've learned the hard way that not remembering to unhook event
I've learned the hard way that regexes cannot adequately parse html, prior to finding
If learned the hard way that you should remove the delegate from an object
I used to install betas freely and learned the hard way that I best
OK, so I've learned the hard way that string comparison works ... differently in
I recently learned the hard way that #<cstdlib> rand() is not thread safe, and
I learned some time ago about Decision Trees and Decision tables. I feel that

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.