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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:07:25+00:00 2026-06-01T17:07:25+00:00

Table Schema For the two tables, the CREATE queries are given below: Table1: (file_path_key,

  • 0

Table Schema

For the two tables, the CREATE queries are given below:

Table1: (file_path_key, dir_path_key)

create table Table1(
             file_path_key varchar(500), 
             dir_path_key varchar(500), 
             primary key(file_path_key)) 
engine = innodb;

Table2: (file_path_key, hash_key)

create table Table2(
             file_path_key varchar(500) not null, 
             hash_key bigint(20) not null, 
             foreign key (file_path_key) references Table1(file_path_key) on update cascade on delete cascade)
engine = innodb;

Objective:

Given a file_path F and it’s dir_path string D, I need to find all those
file names which have at least one hash in the set of hashes of F, but
don’t have their directory names as D. If a file F1 shares multiple hashes
with F, then it should be repeated that many times.

Note that the file_path_key column in Table1 and the hash_key column in Table2 are indexed.

In this particular case, Table1 has around 350,000 entries and Table2 has 31,167,119 entries, which makes my current query slow:

create table temp 
        as select hash_key from Table2 
        where file_path_key = F;

select s1.file_path_key 
        from Table1 as s1 
        join Table2 as s2 
        on s1.file_path_key join 
        temp on temp.hash_key = s2.hash_key 
        where s1.dir_path_key != D

How can I speed up this 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-06-01T17:07:26+00:00Added an answer on June 1, 2026 at 5:07 pm

    I do not understand what is the purpose of temp table, but remember that such table, created with CREATE .. SELECT, does not have any indexes. So at the very least fix that statement to

    CREATE TABLE temp (INDEX(hash_key)) ENGINE=InnoDB AS 
    SELECT hash_key FROM Table2 WHERE file_path_key = F;
    

    Otherwise the other SELECT performs full join with temp, so it might be very slow.

    I would also suggest using a numerical primary key (INT, BIGINT) in Table1 and reference it from Table2 rather than the text column. Eg:

    create table Table1(
                 id int not null auto_increment primary key,
                 file_path_key varchar(500), 
                 dir_path_key varchar(500), 
                 unique key(file_path_key)) 
    engine = innodb;
    
    create table Table2(
                 file_id int not null, 
                 hash_key bigint(20) not null, 
                 foreign key (file_id) references Table1(id) 
                on update cascade on delete cascade) engine = innodb;
    

    Queries joining the two tables may be a lot faster if integer columns are used in join predicate rather than text ones.

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

Sidebar

Related Questions

Table Schema For the two tables, the CREATE queries are given below: Table1: (file_path_key,
I have two tables with the following schema: CREATE TABLE sales_data ( sales_time date
Two temp tables are created and then loaded...Here's the schema. Create table #SH ([date]
I have two tables names book_list and book_category . Schema is like below: book_list
I have two tables, both named as say, Employee in two different schema HR
I have two tables in my database schema that represent an entity having a
I have two tables userdetails and blog question The schema is UserDetails: connection: doctrine
edit: my table schema below is poorly normalized as suggested and I have revamped
Please consider following schema CREATE table articles ( id Int UNSIGNED NOT NULL AUTO_INCREMENT,
I have two tables with the exact same schema in SQL Server 2008 Standard

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.