zrhoffman commented on code in PR #7520:
URL: https://github.com/apache/trafficcontrol/pull/7520#discussion_r1214558370


##########
traffic_ops/traffic_ops_golang/deliveryservice/servers/servers.go:
##########
@@ -895,7 +895,8 @@ func (dss *TODSSDeliveryService) Read(h http.Header, useIMS 
bool) ([]interface{}
        } else {
                where = "WHERE "
        }
-       where += "ds.id in (SELECT deliveryService FROM deliveryservice_server 
where server = :server)"
+
+       where += "ds.id in (SELECT deliveryService FROM deliveryservice_server 
WHERE server = :server) OR ds.id in (SELECT id FROM deliveryservice WHERE 
topology in ( SELECT topology FROM topology_cachegroup WHERE cachegroup = ( 
SELECT name FROM cachegroup WHERE id = ( SELECT cachegroup FROM server WHERE id 
= :server ))))"

Review Comment:
   This is a long line for a query fragment. How about reformatting it as a 
multiline string like this?
   
   ```sql
        where += `
   ds.id in (
        SELECT deliveryService FROM deliveryservice_server WHERE server = 
:server
   ) OR ds.id in (
        SELECT id FROM deliveryservice
        WHERE topology in (
                SELECT topology FROM topology_cachegroup
                WHERE cachegroup = (
                        SELECT name FROM cachegroup
                        WHERE id = (
                                SELECT cachegroup FROM server WHERE id = :server
                        ))))
   `
   ```



##########
traffic_ops/traffic_ops_golang/deliveryservice/servers/servers.go:
##########
@@ -895,7 +895,8 @@ func (dss *TODSSDeliveryService) Read(h http.Header, useIMS 
bool) ([]interface{}
        } else {
                where = "WHERE "
        }
-       where += "ds.id in (SELECT deliveryService FROM deliveryservice_server 
where server = :server)"
+
+       where += "ds.id in (SELECT deliveryService FROM deliveryservice_server 
WHERE server = :server) OR ds.id in (SELECT id FROM deliveryservice WHERE 
topology in ( SELECT topology FROM topology_cachegroup WHERE cachegroup = ( 
SELECT name FROM cachegroup WHERE id = ( SELECT cachegroup FROM server WHERE id 
= :server ))))"

Review Comment:
   In general, accomplishing this with `JOIN`s for the
   
   ```sql
   WHERE topology in ( SELECT topology FROM topology_cachegroup WHERE 
cachegroup = ( SELECT name FROM cachegroup WHERE id = ( SELECT cachegroup FROM 
server WHERE id = :server )))
   ```
   
   instead of subqueries would be possible, but there is probably not a 
performance difference, so keeping this structure is fine.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to