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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:59:50+00:00 2026-05-27T22:59:50+00:00

table1_shard1 (1,000,000 rows per shard x 120 shards) id_user hash table2 (100,000 rows) value

  • 0

table1_shard1 (1,000,000 rows per shard x 120 shards)

 id_user   hash

table2 (100,000 rows)

 value    hash

Desired Output:

 id_user  hash    value

I am trying to find the fastest way to associate id_user with value from the tables above.

My current query ran for 30 hours without result.

SELECT 
    table1_shard1.id_user, table1_shard1.hash, table2.value 
FROM table1_shard1 
LEFT JOIN table2 ON table1_shard1.hash=table2.hash 
GROUP BY id_user
UNION
SELECT 
    table1_shard2.id_user, table1_shard2.hash, table2.value 
FROM table1_shard1 
LEFT JOIN table2 ON table1_shard2.hash=table2.hash 
GROUP BY id_user
UNION 
( ... )
UNION 
SELECT 
    table1_shard120.id_user, table1_shard120.hash, table2.value 
FROM table1_shard1 
LEFT JOIN table2 ON table1_shard120.hash=table2.hash 
GROUP BY id_user
  • 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-27T22:59:50+00:00Added an answer on May 27, 2026 at 10:59 pm

    Firstly, do you have indexes on the hash fields

    I think you should merge your tables in one before the query (at least temporarily)

    CREATE TEMPORARY TABLE IF NOT EXISTS tmp_shards
    SELECT * FROM table1_shard1;
    
    CREATE TEMPORARY TABLE IF NOT EXISTS tmp_shards
    SELECT * FROM table1_shard2;
    
    # ...
    

    Then do the main query

    SELECT
      table1_shard120.id_user
    , table1_shard120.hash
    , table2.value
    FROM tmp_shards AS shd
    LEFT JOIN table2 AS tb2 ON (shd.hash = tb2.hash)
    GROUP BY id_user
    ;
    

    Not sure for the performance gain but it’ll be at least more maintainable.

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

Sidebar

Related Questions

Using Access 2003 Table1 ID Name Value 001 Raja 100 002 Ramu 200 004
I'm trying to shard my database into two: one for my main objects, another
Table table1 has got 500,000 rows. I want insert only 200,000 of them to
Table1: ID,Name,some more columns Table2: ID Table3: Name I want get output from table1,
I have records in table1, if the records exist, it must copy into table2.
I have Table1 and Table2 related on Table1.ID. There can be zero or more
Scaling up memcached to a cluster of shards/partitions requires either distributed routing/partition table maintenance
table1 | id | value -------------------- 1 | john 2 | frank 3 |
Table1: Id MyFK f_name l_name =========================== 1 100 John Doe 2 100 Little Timmy
table1 (id, name) table2 (id, name) Query: SELECT name FROM table2 -- that are

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.