Best way to join table with million rows

Viewed 103

I have 2 tables with more rows.

  1. table FIRM with 500.000 rows;

  2. table FURNISHER with 1.000.000 rows;

Each row of both tables has a PRIMARY id.

Each FIRM row should be merged with approximately 10000 rows of FURNISHER.

For example:

FIRM.id = 3 has this FURNISHER.ids (5,23,67,456,123, ....)

FIRM.id = 7 has this FURNISHER.ids (6,23,1200, ....)

...

What is the best way to save the FURNISHER ids assigned to FIRM?

I need to create an additional table that only holds the relationships between FIRM and FURNISHER tables?

If I create a new table how should it be?

CREATE TABLE `firm_relation` (
  `id` int(10) UNSIGNED NOT NULL,
  `firm_id` int(11) NOT NULL,
  `furnisher_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;



ALTER TABLE `firm_relation`
  ADD PRIMARY KEY (`id`),
  ADD KEY `rel` (`firm_id`,`furnisher_id`);


ALTER TABLE `firm_relation`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;

So I would have about 500.000 x 10.000 rows...

0 Answers
Related