From 19669922dd2393c23371ee1532824e528b897de0 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 15 Sep 2010 21:12:49 +0100 Subject: [PATCH] yarrg database code: eliminate all NATURAL JOINs and turn them into JOIN USING --- yarrg/CommodsDatabase.pm | 25 ++++++++++++++----------- yarrg/commod-email-processor | 1 + yarrg/web/query_age | 2 +- yarrg/web/query_commod | 2 +- yarrg/web/routetrade | 4 ++-- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/yarrg/CommodsDatabase.pm b/yarrg/CommodsDatabase.pm index 3cb543d..999dda7 100644 --- a/yarrg/CommodsDatabase.pm +++ b/yarrg/CommodsDatabase.pm @@ -188,12 +188,13 @@ sub db_check_referential_integrity ($) { nooutput(< 0 GROUP BY commodclassid,posinclass HAVING count(*) > 1; SELECT commodclass,commodclassid,count(*) - FROM commods NATURAL JOIN commodclasses + FROM commods JOIN commodclasses USING (commodclassid) WHERE posinclass > 0 GROUP BY commodclassid HAVING count(*) != maxposinclass; SELECT * - FROM commods NATURAL JOIN commodclasses + FROM commods JOIN commodclasses USING (commodclassid) WHERE posinclass < 0 OR posinclass > maxposinclass; END diff --git a/yarrg/commod-email-processor b/yarrg/commod-email-processor index a75864a..e65b2b6 100755 --- a/yarrg/commod-email-processor +++ b/yarrg/commod-email-processor @@ -197,6 +197,7 @@ sub main () { # print "\n"; db_chkcommit(0); + # Warning! Below runes are bogus. Do not use NATURAL JOIN! # select * from ((buy natural join commods) natural join stalls) natural join islands; # select * from ((sell natural join commods) natural join stalls) natural join islands; diff --git a/yarrg/web/query_age b/yarrg/web/query_age index 4f8ba81..a115bbd 100644 --- a/yarrg/web/query_age +++ b/yarrg/web/query_age @@ -47,7 +47,7 @@ $dbh my $now= time; my $sth= $dbh->prepare("SELECT archipelago, islandid, islandname, timestamp - FROM uploads NATURAL JOIN islands + FROM uploads JOIN islands USING (islandid) ORDER BY archipelago, islandname"); $sth->execute(); diff --git a/yarrg/web/query_commod b/yarrg/web/query_commod index 8d55f26..c801a63 100644 --- a/yarrg/web/query_commod +++ b/yarrg/web/query_commod @@ -99,7 +99,7 @@ foreach my $bs (split /_/, $ARGS{BuySell}) { my $offers= $dbh->prepare( "SELECT stallname, price, qty - FROM $bs NATURAL JOIN stalls + FROM $bs JOIN stalls USING (stallid, islandid) WHERE commodid = ? AND islandid = ? ORDER BY price $ascdesc" ); diff --git a/yarrg/web/routetrade b/yarrg/web/routetrade index 03ef3e1..c62ca60 100644 --- a/yarrg/web/routetrade +++ b/yarrg/web/routetrade @@ -1010,12 +1010,12 @@ END <%perl> my $sth_i= $dbh->prepare(<prepare(<