From: Ian Jackson Date: Wed, 15 Sep 2010 20:12:49 +0000 (+0100) Subject: yarrg database code: eliminate all NATURAL JOINs and turn them into JOIN USING X-Git-Tag: 6.7.0~13 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.main.git;a=commitdiff_plain;h=19669922dd2393c23371ee1532824e528b897de0 yarrg database code: eliminate all NATURAL JOINs and turn them into JOIN USING --- 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(<