I'm interested in how to make this query run faster.
The idea is to insert from one table into another table via update. The catch is that the larger table is is about 150,000 rows with a PK on the item I want to insert. The smaller table has about 125,000 rows. The result I'm looking for is to insert the skus from the larger table into the smaller table so that they have the same amount of rows.
I tried two different queries, but this one is probably the most obvious:
INSERT INTO item_data
(sku)
SELECT sku
FROM item_table
WHERE sku NOT IN (SELECT sku
FROM item_data);
I also tried this variation:
INSERT INTO item_data
(sku)
SELECT t1.sku
FROM (SELECT sku
FROM item_data) AS t1,
(SELECT sku
FROM item_table) AS t2
WHERE t1.sku <> t2.sku
(sorry if the syntax is a bit off here).
I started by running the base select query, and to my dismay, it was extremely slow.
I'm guessing that I should try different joins on for size, but I'm also interested in knowing why this query runs slower than it appears to at first blush, and if possible, what I should look for in identifying why this one runs slow.
This is a fresh install and a new database with no indices or anything else but a few tables, running the latest PgAdmin.