Robert Pelletier writes:
> If we chose to work with 1 partition / week controlled within the
> application, the absolute fastest way to delete the data is to drop
> the partition. (ALTER TABLE myTable DROP PARTITION myPartition)

I have now a somewhat more advanced variant of my previously posted patch,
which automatically sets partition_tag to a current ISO8601 week number
(1..53) if $sql_partition_tag is undef, which will be a default.
If anyone is interested please drop me a line.

A requirement is to add a field 'partition_tag' into tables maddr, msgs,
msgrcpt and quarantine, as posted previously - except that I did the
last constraint (and implicit index) on maddr incorrectly, it should
be UNIQUE (partition_tag,email)  (and not: UNIQUE(partition_tag,id) ).

Here it goes again, correctly this time:

ALTER TABLE msgs       ADD partition_tag integer DEFAULT 0;
ALTER TABLE msgrcpt    ADD partition_tag integer DEFAULT 0;
ALTER TABLE quarantine ADD partition_tag integer DEFAULT 0;
ALTER TABLE maddr      ADD partition_tag integer DEFAULT 0;
ALTER TABLE maddr DROP CONSTRAINT maddr_email_key;
ALTER TABLE maddr ADD  CONSTRAINT maddr_email_key UNIQUE (partition_tag,email);

I assume the ADD CONSTRAINT will implicitly create an index
on multicolumn key (partition_tag,email).
(otherwise it must be created explicitly, otherwise inserting
of mail addresses will be slow).

Amavisd does not care about partition_tag for its operations, it sees
all entries regardless of partition_tag, e.g. for its pen pals lookups.
All it does is provide this additional information in tables; what
one does with it is up to oneself (most small sites would just ignore
the extra information). But of course, it lands itself naturally
to partitioning.

> This could add quite a bit of code (detecting which MySQL version
> we are running on, etc.).

None of this code is within amavisd. Automating purging and
providing procedures for this is up to a SQL administrator - and
he know what database server is used, home-grown procedures
need not be general-purpose.

> Application-wise, the simplest way to implement it would be to partition by
> hash. Like I said, I'm not familiar with your schema and can't seam to find
> it in my distribution.

http://www.ijs.si/software/amavisd/#doc
-> README.sql, README.sql-mysql, README.sql-pg

> If time_num or time_iso is a MySQL recognized time 
> format, we could partition per hash using the date function yearweek.

Yes, except for the fact that timestamp is currently only kept
in a msgs table. Tables carying child information do not carry
a timestamp, which is one reason they can't be partitioned
as-they-are (at least not the way it would help with purging).

Another problem is that records in table maddr (carrying all mail
addresses encountered, sender or recipient) are reused whenever
a mail address re-occurs, so even if timestamp would be added
to this table, it would not help, because old entry may be
referenced from a fresh msgs record.

This is a reason that code modification is necessary (as in posted
patch or my current code). It guarantees that maddr records are local
to a partition_tag from which they are referenced (from msgs or msgrcpt).

If a particular partition_tag from msgs is dropped, it is now
safe to also drop records with the same partition_tag from
all subordinate tables (msgrcpt, maddr, quarantine).

> We could go further and create 53 partitions, and be shure to have
> only 1 week of data in it (but having 48/49 empty partitions).
> We'd get more than a week of data if we were to keep more than
> 1 year or messages.

Yes, this is what I have in mind as a typical setup.
Have all 53 partitions present, most of them being empty.
A weekly maintenance operation would drop one (or few) oldest
weekly partitions, and re-create empty partitions.
Instant maintenance, not affecting amavisd normal operation.

  Mark

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
AMaViS-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/amavis-user
AMaViS-FAQ:http://www.amavis.org/amavis-faq.php3
AMaViS-HowTos:http://www.amavis.org/howto/

Reply via email to