]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1428] Use SQL select 1 consistently
authorMarcin Siodelski <marcin@isc.org>
Thu, 1 Oct 2020 11:59:39 +0000 (13:59 +0200)
committerMarcin Siodelski <marcin@isc.org>
Mon, 5 Oct 2020 13:14:58 +0000 (13:14 +0000)
The new INSERT SELECT statements are also better described to explain why
SELECT 1 is used as a result of the review.

src/lib/dhcpsrv/mysql_host_data_source.cc
src/lib/dhcpsrv/pgsql_host_data_source.cc

index bc006f58d3826ec1bb35eba95a32299267b492f2..fb19fac700e3d1203fb11104a38dce3f3d8a13b3 100644 (file)
@@ -2608,10 +2608,13 @@ TaggedStatementArray tagged_statements = { {
 
     // Inserts a host into the 'hosts' table with checking that reserved IP
     // address is unique. The innermost query checks if there is at least
-    // one host for the given IP/subnet combination. If it not exists the
-    // new host is inserted. DUAL is a special MySQL table from which we
-    // can select the values to be inserted. If the host with the given
-    // IP address already exists the new host won't be inserted. The caller
+    // one host for the given IP/subnet combination. For checking whether
+    // hosts exists or not it doesn't matter if we select actual columns,
+    // thus SELECT 1 was used as an optimization to avoid selecting data
+    // that will be ignored anyway. If the host does not exist the new
+    // host is inserted. DUAL is a special MySQL table from which we can
+    // select the values to be inserted. If the host with the given IP
+    // address already exists the new host won't be inserted. The caller
     // can check the number of affected rows to detect that there was
     // a duplicate host in the database.
     {MySqlHostDataSourceImpl::INSERT_HOST_UNIQUE_IP,
@@ -2622,7 +2625,7 @@ TaggedStatementArray tagged_statements = { {
                 "dhcp4_server_hostname, dhcp4_boot_file_name, auth_key) "
                 "SELECT ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? FROM DUAL "
                     "WHERE NOT EXISTS ("
-                        "SELECT ipv4_address FROM hosts "
+                        "SELECT 1 FROM hosts "
                             "WHERE ipv4_address = ? AND dhcp4_subnet_id = ? "
                         "LIMIT 1"
                     ")"},
index abc3c838117f2cd258f5a41627fa0bd2093bbfcf..edbc630951309df099b278ed4a25932d7496f538 100644 (file)
@@ -2009,11 +2009,14 @@ TaggedStatementArray tagged_statements = { {
     // PgSqlHostDataSourceImpl::INSERT_HOST_UNIQUE_IP
     // Inserts a host into the 'hosts' table with checking that reserved IP
     // address is unique. The innermost query checks if there is at least
-    // one host for the given IP/subnet combination. If it not exists the
-    // new host is inserted. If the host with the given IP address already
-    // exists the new host won't be inserted. The caller can check the
-    // number of affected rows to detect that there was a duplicate host
-    // in the database. Returns the inserted host id.
+    // one host for the given IP/subnet combination. For checking whether
+    // hosts exists or not it doesn't matter if we select actual columns,
+    // thus SELECT 1 was used as an optimization to avoid selecting data
+    // that will be ignored anyway. If it does not exist the new host is
+    // inserted. If the host with the given IP address already exists the
+    // new host won't be inserted. The caller can check the number of
+    // affected rows to detect that there was a duplicate host in the
+    // database. Returns the inserted host id.
     {15,
      { OID_BYTEA, OID_INT2,
        OID_INT8, OID_INT8, OID_INT8, OID_VARCHAR,