The first INSERT needs an ORDER BY clause, or we could end up with inconsistent data between the master and slave databases:
INSERT INTO DistributionSourcePackage (distribution,sourcepackagename)
SELECT ds.distribution, sourcepackagename
FROM SourcePackagePublishingHistory spph
JOIN Archive ON spph.archive = Archive.id
JOIN SourcePackageRelease spr ON spph.sourcepackagerelease = spr.id
JOIN DistroSeries ds ON spph.distroseries = ds.id
WHERE ds.releasestatus = 4 -- CURRENT
AND Archive.purpose = 1 -- PRIMARY
EXCEPT
SELECT distribution, sourcepackagename
FROM DistributionSourcePackage
ORDER BY distribution, sourcepackagename;
We also need to repack the table when we are done, so add at the end:
CLUSTER DistributionSourcePackage
USING distributionpackage__sourcepackagename__distribution__key;
The first INSERT needs an ORDER BY clause, or we could end up with inconsistent data between the master and slave databases:
INSERT INTO DistributionSou rcePackage (distribution, sourcepackagena me) blishingHistory spph lease spr ON spph.sourcepack agerelease = spr.id rcePackage
SELECT ds.distribution, sourcepackagename
FROM SourcePackagePu
JOIN Archive ON spph.archive = Archive.id
JOIN SourcePackageRe
JOIN DistroSeries ds ON spph.distroseries = ds.id
WHERE ds.releasestatus = 4 -- CURRENT
AND Archive.purpose = 1 -- PRIMARY
EXCEPT
SELECT distribution, sourcepackagename
FROM DistributionSou
ORDER BY distribution, sourcepackagename;
We also need to repack the table when we are done, so add at the end:
CLUSTER DistributionSou rcePackage kage__sourcepac kagename_ _distribution_ _key;
USING distributionpac