diff -ur orig/pdns-2.9.15/modules/gmysqlbackend/gmysqlbackend.cc pdns-2.9.15/modules/gmysqlbackend/gmysqlbackend.cc
--- orig/pdns-2.9.15/modules/gmysqlbackend/gmysqlbackend.cc	Tue Jan 14 10:23:45 2003
+++ pdns-2.9.15/modules/gmysqlbackend/gmysqlbackend.cc	Wed Feb 25 17:45:48 2004
@@ -72,6 +72,7 @@
     declare(suffix,"update-lastcheck-query","", "update domains set last_check=%d where id=%d");
     declare(suffix,"info-all-master-query","", "select id,name,master,last_check,notified_serial,type from domains where type='MASTER'");
     declare(suffix,"delete-zone-query","", "delete from records where domain_id=%d");
+    declare(suffix,"zone-serial-query","", "select max(change_date) from records where domain_id=%d");
 
 
   }
diff -ur orig/pdns-2.9.15/modules/gpgsqlbackend/gpgsqlbackend.cc pdns-2.9.15/modules/gpgsqlbackend/gpgsqlbackend.cc
--- orig/pdns-2.9.15/modules/gpgsqlbackend/gpgsqlbackend.cc	Fri Jan 16 14:53:45 2004
+++ pdns-2.9.15/modules/gpgsqlbackend/gpgsqlbackend.cc	Wed Feb 25 17:46:15 2004
@@ -73,6 +73,7 @@
     declare(suffix,"update-lastcheck-query","", "update domains set last_check=%d where id=%d");
     declare(suffix,"info-all-master-query","", "select id,name,master,last_check,notified_serial,type from domains where type='MASTER'");
     declare(suffix,"delete-zone-query","", "delete from records where domain_id=%d");
+    declare(suffix,"zone-serial-query","", "select max(change_date) from records where domain_id=%d");
 
 
   }
diff -ur orig/pdns-2.9.15/pdns/backends/gsql/gsqlbackend.cc pdns-2.9.15/pdns/backends/gsql/gsqlbackend.cc
--- orig/pdns-2.9.15/pdns/backends/gsql/gsqlbackend.cc	Fri Jan 16 17:18:12 2004
+++ pdns-2.9.15/pdns/backends/gsql/gsqlbackend.cc	Wed Feb 25 17:48:47 2004
@@ -238,6 +238,7 @@
   d_UpdateLastCheckofZoneQuery=getArg("update-lastcheck-query");
   d_InfoOfAllMasterDomainsQuery=getArg("info-all-master-query");
   d_DeleteZoneQuery=getArg("delete-zone-query");
+  d_ZoneSerialQuery=getArg("zone-serial-query");
 }
 
 
@@ -341,6 +342,25 @@
     }
   }
   return false;
+}
+
+u_int32_t GSQLBackend::fetchZoneSerial(u_int32_t domain_id)
+{
+
+  string format;
+  char output[1024];
+  format = d_ZoneSerialQuery;
+  snprintf(output, sizeof(output)-1, format.c_str(), domain_id);
+  try {
+    d_db->doQuery(output, d_result);
+  }
+  catch(SSqlException &e) {
+    throw AhuException("Database error trying to query serial for domain_id "+itoa(domain_id)+": "+e.txtReason());
+  }
+  if(!d_result.empty()) {
+    return (atoi(d_result[0][0].c_str()));
+  }
+  return 0;
 }
 
 bool GSQLBackend::createSlaveDomain(const string &ip, const string &domain, const string &account)
diff -ur orig/pdns-2.9.15/pdns/backends/gsql/gsqlbackend.hh pdns-2.9.15/pdns/backends/gsql/gsqlbackend.hh
--- orig/pdns-2.9.15/pdns/backends/gsql/gsqlbackend.hh	Sat Aug 23 10:35:35 2003
+++ pdns-2.9.15/pdns/backends/gsql/gsqlbackend.hh	Wed Feb 25 17:49:41 2004
@@ -33,6 +33,7 @@
   bool feedRecord(const DNSResourceRecord &r);
   bool createSlaveDomain(const string &ip, const string &domain, const string &account);
   bool superMasterBackend(const string &ip, const string &domain, const vector<DNSResourceRecord>&nsset, string *account, DNSBackend **db);
+  u_int32_t fetchZoneSerial(u_int32_t domain_id);
   void setFresh(u_int32_t domain_id);
   void getUnfreshSlaveInfos(vector<DomainInfo> *domains);
   void getUpdatedMasters(vector<DomainInfo> *updatedDomains);
@@ -66,5 +67,6 @@
   string d_UpdateLastCheckofZoneQuery;
   string d_InfoOfAllMasterDomainsQuery;
   string d_DeleteZoneQuery;		
+  string d_ZoneSerialQuery;
 
 };
diff -ur orig/pdns-2.9.15/pdns/dnsbackend.cc pdns-2.9.15/pdns/dnsbackend.cc
--- orig/pdns-2.9.15/pdns/dnsbackend.cc	Fri Oct 24 13:33:55 2003
+++ pdns-2.9.15/pdns/dnsbackend.cc	Wed Feb 25 17:52:38 2004
@@ -231,6 +231,11 @@
   if(sd.hostmaster.empty())
     sd.hostmaster="hostmaster."+domain;
 
+  // try to let the backend be smart and figure this out for us faster. this
+  // should replace the following sub-optimal method.
+  if(!sd.serial)
+    sd.serial = this->fetchZoneSerial(sd.domain_id);
+
   if(!sd.serial) { // magic time!
     DLOG(L<<Logger::Warning<<"Doing soa serialnumber autocalculation for "<<rr.qname<<endl);
 
diff -ur orig/pdns-2.9.15/pdns/dnsbackend.hh pdns-2.9.15/pdns/dnsbackend.hh
--- orig/pdns-2.9.15/pdns/dnsbackend.hh	Sat Aug 23 10:35:35 2003
+++ pdns-2.9.15/pdns/dnsbackend.hh	Wed Feb 25 17:51:48 2004
@@ -169,6 +169,11 @@
     return false;
   }
 
+  virtual u_int32_t fetchZoneSerial(u_int32_t domain_id)
+  {
+    return 0;
+  }
+
 protected:
   bool mustDo(const string &key);
   const string &getArg(const string &key);
