BIND 10 master, updated. b9b899343170f79cd26929245180180c850d5594 [2301] Add comment for ANY_SUB query

BIND 10 source code commits bind10-changes at lists.isc.org
Tue Oct 2 13:35:18 UTC 2012


The branch, master has been updated
       via  b9b899343170f79cd26929245180180c850d5594 (commit)
       via  84d2f3799c493862a22e7b873352da9db766a19d (commit)
      from  f5811cdff640338babcf1ca0b4cfc7a06580a4f5 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit b9b899343170f79cd26929245180180c850d5594
Author: Mukund Sivaraman <muks at isc.org>
Date:   Tue Oct 2 19:00:02 2012 +0530

    [2301] Add comment for ANY_SUB query

commit 84d2f3799c493862a22e7b873352da9db766a19d
Author: Mukund Sivaraman <muks at isc.org>
Date:   Mon Oct 1 01:37:11 2012 +0530

    [2301] Update ANY_SUB query to use LIKE clause efficiently
    
    See <https://lists.isc.org/pipermail/bind10-dev/2012-March/003167.html>
    for discussion.
    
    We should not do concatenation in the SQL clause (i.e., pass an
    expression to LIKE).  We also query on the 'rname' column (labels in
    reverse order) instead of 'name'.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/datasrc/sqlite3_accessor.cc |   36 +++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/sqlite3_accessor.cc b/src/lib/datasrc/sqlite3_accessor.cc
index 24d7b3f..672121e 100644
--- a/src/lib/datasrc/sqlite3_accessor.cc
+++ b/src/lib/datasrc/sqlite3_accessor.cc
@@ -20,6 +20,8 @@
 
 #include <exceptions/exceptions.h>
 
+#include <dns/name.h>
+
 #include <datasrc/sqlite3_accessor.h>
 #include <datasrc/logger.h>
 #include <datasrc/data_source.h>
@@ -84,8 +86,13 @@ const char* const text_statements[NUM_STATEMENTS] = {
     "SELECT id FROM zones WHERE name=?1 AND rdclass = ?2", // ZONE
     "SELECT rdtype, ttl, sigtype, rdata FROM records "     // ANY
         "WHERE zone_id=?1 AND name=?2",
-    "SELECT rdtype, ttl, sigtype, rdata " // ANY_SUB
-        "FROM records WHERE zone_id=?1 AND name LIKE (\"%.\" || ?2)",
+
+    // ANY_SUB:
+    // This query returns records in the specified zone for the domain
+    // matching the passed name, and its sub-domains.
+    "SELECT rdtype, ttl, sigtype, rdata "
+        "FROM records WHERE zone_id=?1 AND rname LIKE ?2",
+
     "BEGIN",                    // BEGIN
     "COMMIT",                   // COMMIT
     "ROLLBACK",                 // ROLLBACK
@@ -660,17 +667,27 @@ public:
         statement_(NULL),
         name_(name)
     {
-        // Choose the statement text depending on the query type
-        const char* statement(NULL);
+        // Choose the statement text depending on the query type, and
+        // prepare a statement to get data from it.
         switch (qtype) {
             case QT_ANY:
-                statement = text_statements[ANY];
+                statement_ = prepare(accessor->dbparameters_->db_,
+                                     text_statements[ANY]);
+                bindZoneId(id);
+                bindName(name_);
                 break;
             case QT_SUBDOMAINS:
-                statement = text_statements[ANY_SUB];
+                statement_ = prepare(accessor->dbparameters_->db_,
+                                     text_statements[ANY_SUB]);
+                bindZoneId(id);
+                // Done once, this should not be very inefficient.
+                bindName(isc::dns::Name(name_).reverse().toText() + "%");
                 break;
             case QT_NSEC3:
-                statement = text_statements[NSEC3];
+                statement_ = prepare(accessor->dbparameters_->db_,
+                                     text_statements[NSEC3]);
+                bindZoneId(id);
+                bindName(name_);
                 break;
             default:
                 // Can Not Happen - there isn't any other type of query
@@ -680,11 +697,6 @@ public:
                           "Invalid qtype passed - unreachable code branch "
                           "reached");
         }
-
-        // We create the statement now and then just keep getting data from it
-        statement_ = prepare(accessor->dbparameters_->db_, statement);
-        bindZoneId(id);
-        bindName(name_);
     }
 
     bool getNext(std::string (&data)[COLUMN_COUNT]) {



More information about the bind10-changes mailing list