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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:51:37+00:00 2026-05-14T23:51:37+00:00

(Using Oracle) I have a table with key/value pairs like this: create table MESSAGE_INDEX

  • 0

(Using Oracle)

I have a table with key/value pairs like this:

create table MESSAGE_INDEX
(
  KEY               VARCHAR2(256) not null,
  VALUE             VARCHAR2(4000) not null,
  MESSAGE_ID        NUMBER not null
)

I now want to find all the messages where key = ‘someKey’ and value is ‘val1’, ‘val2’ or ‘val3’ – OR value is null in which case there will be no entry in the table at all. This is to save space; there would be a large number of keys with null values if I stored them all.

I think this works:

SELECT message_id
FROM message_index idx
WHERE ((key = 'someKey' AND value IN ('val1', 'val2', 'val3'))
      OR NOT EXISTS (SELECT 1 FROM message_index WHERE key = 'someKey'
      AND idx.message_id = message_id))

But is is extremely slow. Takes 8 seconds with 700K records in message_index and there will be many more records and more search criteria when moving outside of my test environment.

Primary key is key, value, message_id:

  add constraint PK_KEY_VALUE primary key (KEY, VALUE, MESSAGE_ID)

And I added another index for message_id, to speed up searching for missing keys:

create index IDX_MESSAGE_ID on MESSAGE_INDEX (MESSAGE_ID)

I will be doing several of these key/value lookups in every search, not just one as shown above. So far I am doing them nested, where output id’s of one level is the input to the next. E.g.:

SELECT message_id from message_index
WHERE (key/value compare)
AND message_id IN
  (
    SELECT ... and so on
  )

What can I do to speed this up?

  • 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-14T23:51:38+00:00Added an answer on May 14, 2026 at 11:51 pm

    If you have a key that all messages are guaranteed to have:

    SELECT  message_id
    FROM    message_index mi
    WHERE   mi.key = 'GuaranteedKey'
            AND mi.message_id IN
            (
            SELECT  message_id
            FROM    message_index mk
            WHERE   mk.key = 'someKey'
                    AND mk.value IN (1, 2, 3)
            )
    UNION ALL
    SELECT  message_id
    FROM    message_index mi
    WHERE   mi.key = 'GuaranteedKey'
            AND mi.message_id NOT IN
            (
            SELECT  message_id
            FROM    message_index mk
            WHERE   mk.key = 'someKey'
            )
    

    If you don’t:

    WITH    mi AS
            (
            SELECT  DISTINCT message_id
            FROM    message_index
            )
    SELECT  message_id
    FROM    mi
    WHERE   mi.message_id IN
            (
            SELECT  message_id
            FROM    message_index mk
            WHERE   mk.key = 'someKey'
                    AND mk.value IN (1, 2, 3)
            )
    UNION ALL
    SELECT  message_id
    FROM    mi
    WHERE   mi.message_id NOT IN
            (
            SELECT  message_id
            FROM    message_index mk
            WHERE   mk.key = 'someKey'
            )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 477k
  • Answers 477k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Passing a message from ViewModel1 to View1 means to use… May 16, 2026 at 5:16 am
  • Editorial Team
    Editorial Team added an answer for instance: ImageList imgList = new ImageList(); imgList.Images.AddStrip(bitmap); this.listView1.StateImageList =… May 16, 2026 at 5:16 am
  • Editorial Team
    Editorial Team added an answer Here's the United States FBI Biometrics website. I found the… May 16, 2026 at 5:16 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.