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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:22:36+00:00 2026-06-09T01:22:36+00:00

Let say we have a table with 6 million records. There are 16 integer

  • 0

Let say we have a table with 6 million records. There are 16 integer columns and few text column. It is read-only table so every integer column have an index.
Every record is around 50-60 bytes.

The table name is “Item”
The server is: 12 GB RAM, 1,5 TB SATA, 4 CORES. All server for postgres.
There are many more tables in this database so RAM do not cover all database.

I want to add to table “Item” a column “a_elements” (array type of big integers)
Every record would have not more than 50-60 elements in this column.

After that i would create index GIN on this column and typical query should look like this:

select * from item where ...... and '{5}' <@ a_elements;

I have also second, more classical, option.

Do not add column a_elements to table item but create table elements with two columns:

  • id_item
  • id_element

This table would have around 200 mln records.

I am able to do partitioning on this tables so number of records would reduce to 20 mln in table elements and 500 K in table item.

The second option query looks like this:

select item.* 
from item 
    left join elements on (item.id_item=elements.id_item) 
where .... 
and 5 = elements.id_element

I wonder what option would be better at performance point of view.
Is postgres able to use many different indexes with index GIN (option 1) in a single query ?

I need to make a good decision because import of this data will take me a 20 days.

  • 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-09T01:22:38+00:00Added an answer on June 9, 2026 at 1:22 am

    I think you should use an elements table:

    • Postgres would be able to use statistics to predict how many rows will match before executing query, so it would be able to use the best query plan (it is more important if your data is not evenly distributed);

    • you’ll be able to localize query data using CLUSTER elements USING elements_id_element_idx;

    • when Postgres 9.2 would be released then you would be able to take advantage of index only scans;

    But I’ve made some tests for 10M elements:

    create table elements (id_item bigint, id_element bigint);
    insert into elements
      select (random()*524288)::int, (random()*32768)::int
        from generate_series(1,10000000);
    
    \timing
    create index elements_id_item on elements(id_item);
    Time: 15470,685 ms
    create index elements_id_element on elements(id_element);
    Time: 15121,090 ms
    
    select relation, pg_size_pretty(pg_relation_size(relation))
      from (
        select unnest(array['elements','elements_id_item', 'elements_id_element'])
          as relation
      ) as _;
          relation       | pg_size_pretty 
    ---------------------+----------------
     elements            | 422 MB
     elements_id_item    | 214 MB
     elements_id_element | 214 MB
    
    
    
    create table arrays (id_item bigint, a_elements bigint[]);
    insert into arrays select array_agg(id_element) from elements group by id_item;
    
    create index arrays_a_elements_idx on arrays using gin (a_elements);
    Time: 22102,700 ms
    
    select relation, pg_size_pretty(pg_relation_size(relation))
      from (
        select unnest(array['arrays','arrays_a_elements_idx']) as relation
      ) as _;
           relation        | pg_size_pretty 
    -----------------------+----------------
     arrays                | 108 MB
     arrays_a_elements_idx | 73 MB
    

    So in the other hand arrays are smaller, and have smaller index. I’d do some 200M elements tests before making a decision.

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

Sidebar

Related Questions

Let's say I have a table with a Color column. Color can have various
Let's say I have a table called messages with the columns: id | from_id
Let's say i have a table in a database with 10k records. I dont
Let's say I have a table that has user_id, date, score, and every user
Let's say I have table with column 'URL' whrere I store urls like this
Let's say I have a table tbl with columns id and title . I
Let say i have 100k records in table, after fetching that records from table
Let's say we have a table that has 2 million rows. It has two
Let's say I have a table called 'species' with 3 columns: 'Id', 'ancestorId' and
Let's say I have a table with millions of rows in which I have

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.