New version of some SQL used with quota enforcement that performs much
better at scale.

This new SQL and supporting mods in the ICAT function
(generateSpecialQuery) were provided by Giacomo Mariani and colleagues
at SuperComputing Applications and Innovation Department CINECA,
Bologna, Italy, after investigating SQL that was running very slowly.

I also checked the new SQL by hand to convince myself that the old and
new SQL statements are logically equivalent, although both of them are
a bit complicated.  It helps to work with the statements with a text
editor, breaking them up into components (for the new, by the UNIONs).
The new SQL is doing a UNION of 3 selects, the first of which is
handling group quotas on specific-resources, the second is group
quotas on total use, and the third is for both specific-resources and
total-usage for the particular user.  It seems to be logically
equivalent to the old version where the old had two OR conditions in
some nested conditions (the new form there's one OR, and it's in the
last select of the three).  One minor change from that provided is
removing a trailing ';' on the SQL; this is not an issue with Postgres
but may be with others.

The two queries in this ICAT function are used when quotas are being
enforced (i.e. by enabling quotas via the acRescQuotaPolicy rule in
the core.re file).  There's a setRescQuota function that is called
from the rsDataObjCreate API function, that calls chlGenQuery with
this special option (QUOTA_QUERY).

There are two SQL forms, but it's the second one, quotaQuery2, that is
used in practice (as called by the rsDataObjCreate API function).

I also made some minor changes to logging in the function, changing
some rodsLog calls that were LOG_ERROR to LOG_DEBUG and I added some
(also only at LOG_DEBUG (i.e. normally not logged)).

As part of this commit, I've also updated the quotaTest.pl script to
test this SQL.  See the instructions at the start of the script.  One
needs to enable the enforcement via core.re first, and then run
'quotaTest.pl enabled'.  But this test confirms that that SQL runs OK
and that that quotas are enforced in the various modes (for users or
groups, on particular resources or for total storage).  It's still
worthwhile to run 'quotaTest.pl' without the 'enabled' option (with it
off in core.re) to perform other tests.

Thanks to Giacomo Mariani and colleagues for this improvement.



git-svn-id: svn://irodssvn.ucsd.edu/trunk@5465 ea137bd6-aa86-47b6-b90d-b101d9f19a90