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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:17:56+00:00 2026-05-20T21:17:56+00:00

I have two tables: Articles that stores information about Articles, and PageLinks that stores

  • 0

I have two tables: Articles that stores information about Articles, and PageLinks that stores hyperlinks between pages. The schema is as below.

CREATE TABLE `Articles` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `slug` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `label` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `slug_UNIQUE` (`slug`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

CREATE TABLE `PageLinks` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `from_id` int(11) NOT NULL,
  `to_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `index4` (`to_id`,`from_id`),
  KEY `fk_PageLinks_1` (`from_id`),
  KEY `fk_PageLinks_2` (`to_id`),
  CONSTRAINT `fk_PageLinks_1` FOREIGN KEY (`from_id`) REFERENCES `Articles` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `fk_PageLinks_2` FOREIGN KEY (`to_id`) REFERENCES `Articles` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

I have several million slug pairs that indicate hyperlinks between corresponding pages. I am trying to load the PageLinks table from these slug pairs.

Currently, i have a python program that issues select id queries for each slug to convert the slug pairs to Article id pairs. The id pairs are then written to a file and loaded using load data infile. Additionally if a slug does not exist in the Articles table, the program inserts a dummy row without label and then uses id of that row.

I am trying to optimize the program to load entries faster (I have around 18GB of slug pairs to load). I believe some speed up can be achieved if it is possible to do slug->id resolution and page link insertion together in bulk (thus avoiding the per SELECT overhead). What is the best possible way to do this in mysql?

  • 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-20T21:17:57+00:00Added an answer on May 20, 2026 at 9:17 pm

    Making a separate SELECT for each slug is inefficient indeed.

    You should load your slug pairs into a table:

    CREATE TABLE pairs
            (
            slug1 VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
            slug2 VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
            );
    

    , load it with your pairs, then issue the following statements:

    INSERT IGNORE
    INTO    Articles (slug)
    SELECT  slug1
    FROM    pairs;
    
    INSERT IGNORE
    INTO    Articles (slug)
    SELECT  slug2
    FROM    pairs;
    
    INSERT
    INTO    pairs (from_id, to_id)
    SELECT  a1.id, a2.id
    FROM    pairs
    JOIN    articles a1
    ON      a1.slug = slug1
    JOIN    articles a2
    ON      a2.slug = slug2;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got two tables (articles and tags) that have a one-to-many relationship. I remember
I have two tables: articles and articletags articles: id, author, date_time, article_text articletags: id,
I have two tables that are joined together. A has many B Normally you
I have two tables, one that contains volunteers, and one that contains venues. Volunteers
I have two tables say, t1 and t2 that have t1.t1_id and t2.t2_id as
Quick question that requires a long explanation.. Say I have two tables - one
I have two tables, articles and logs . When new record is inserted into
Let's assume I have a database with two tables: categories and articles . Every
I have two tables in my database. cat - catid, catname articles - id,
Ok, I have two tables that I am joining and doing a select on

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.