Thread: alloc error on multiple action-queries within a rule

alloc error on multiple action-queries within a rule

From
pgsql-bugs@postgresql.org
Date:
clemens oertel (oertel@uni-tuebingen.de) reports a bug with a severity of 2
The lower the number the more severe it is.

Short Description
alloc error on multiple action-queries within a rule

Long Description
when executing the rule 'tax_genuses_del' (see sample code) postgresql reports 'ERROR:  Memory exhausted in
AllocSetAlloc(20)'.each of the the two action-queries runs perfectly by itself, as does the rule with only one of them.
neitheraction (update and insert) takes place. 

please do not hesitate to contact me if any further information is needed.

PostgreSQL Version: 7.1.2
PostgreSQL startup: /usr/local/bin/postmaster -D /home/pgsql -i (postgres)
OS: FreeBSD 4.2 release i386, AMD Duron, 256MB

Log-File:
TopMemoryContext: 40984 total in 5 blocks; 21896 free (29 chunks); 19088 used
TopTransactionContext: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used
DeferredTriggerXact: 8192 total in 1 blocks; 8104 free (0 chunks); 88 used
TransactionCommandContext: 266330112 total in 42 blocks; 544 free (1 chunks); 266329568 used
QueryContext: 57344 total in 3 blocks; 11768 free (0 chunks); 45576 used
DeferredTriggerSession: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used
CacheMemoryContext: 516096 total in 6 blocks; 122976 free (66 chunks); 393120 used
tax_genuses: 72704 total in 71 blocks; 1392 free (0 chunks); 71312 used
pg_rules: 5120 total in 5 blocks; 120 free (0 chunks); 5000 used
pg_user: 5120 total in 5 blocks; 912 free (0 chunks); 4208 used
PortalMemory: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used
MdSmgr: 8192 total in 1 blocks; 6120 free (0 chunks); 2072 used
DynaHash: 57344 total in 3 blocks; 30688 free (5 chunks); 26656 used
ErrorContext: 8192 total in 1 blocks; 8176 free (0 chunks); 16 used
ERROR:  Memory exhausted in AllocSetAlloc(20)


Sample Code
CREATE TABLE _tax_genuses (
  ins_on            TIMESTAMP,
  ins_by            VARCHAR(8),
  upd_on            TIMESTAMP,
  upd_by            VARCHAR(8),
  upd_count         INT2,
  deleted             BOOL,

  id                SERIAL,
  tfamily           INT4              NOT NULL,
  name              TEXT            NOT NULL,
  author            TEXT,

  CONSTRAINT tgenus_id PRIMARY KEY (id),
);

CREATE TABLE hist_tax_genuses AS SELECT * FROM _tax_genuses;

CREATE VIEW tax_genuses AS
  SELECT g.ins_on, g.ins_by, g.upd_on, g.upd_by, g.upd_count, g.id, g.tfamily, g.name, g.author
    FROM _tax_genuses g
      JOIN _tax_families f ON g.tfamily=f.id AND f.deleted=false
      JOIN _tax_orders o ON f.torder=o.id AND o.deleted=false
      JOIN _tax_classes c ON o.tclass=c.id AND c.deleted=false
      JOIN _tax_realms r ON c.trealm=r.id AND r.deleted=false
    WHERE g.deleted=false;

CREATE RULE tax_genuses_del AS
  ON DELETE TO tax_genuses DO INSTEAD
   (UPDATE _tax_genuses
      SET upd_on=now(), upd_by=current_user, upd_count=OLD.upd_count + 1, deleted=true
      WHERE id=OLD.id;
    INSERT INTO hist_tax_genuses SELECT * FROM _tax_genuses WHERE id=OLD.id);

INSERT INTO tax_genuses VALUES (NULL, NULL, NULL, NULL, NULL, NULL, 1, 'Ustlago', 'Oertel');
INSERT INTO tax_genuses VALUES (NULL, NULL, NULL, NULL, NULL, NULL, 1, 'Farysia', 'Oertel');
INSERT INTO tax_genuses VALUES (NULL, NULL, NULL, NULL, NULL, NULL, 1, 'Websdanea', 'Oertel');
INSERT INTO tax_genuses VALUES (NULL, NULL, NULL, NULL, NULL, NULL, 1, 'Cintractia', 'Oertel');

DELETE FROM tax_aliases WHERE id=4;

-- BOOM

No file was uploaded with this report

Re: alloc error on multiple action-queries within a rule

From
Tom Lane
Date:
pgsql-bugs@postgresql.org writes:
> please do not hesitate to contact me if any further information is needed.

Unfortunately your sample code is far from complete --- I got as far as
noticing that there were no declarations for tables  _tax_families,
_tax_orders, _tax_classes, _tax_realms, no ON INSERT rule for view
_tax_genuses, and nothing at all about tax_aliases, before giving up.

Please submit a complete dump script that can be loaded into an empty
database to set up the failure scenario.

It's possible that the problem is the same as one we already noticed
and fixed --- see
http://www.ca.postgresql.org/cgi/cvsweb.cgi/pgsql/src/backend/rewrite/rewriteHandler.c
You could try replacing rewriteHandler.c with version 1.93.2.1 from that
page and see if your problem goes away.

            regards, tom lane