Repository: rucio/rucio

Issue:
Add query hint to judge-evaluator query
Motivation
----------
For unexplained reasons the oracle-optimizer changed the query at
https://github.com/rucio/rucio/blob/fe6eb2e9cd7e1bc9464b955aa0a7d974c961fe82/lib/rucio/core/rule.py#L2558
to a fast full index scan, instead of a PK lookup.

Modification
------------
Add protection by forcing `/*+ INDEX_RS_ASC(atlas_rucio.contents contents_pk)` the PK of the table.




Discussion:

Resolving patch:
diff --git a/lib/rucio/core/rule.py b/lib/rucio/core/rule.py
--- a/lib/rucio/core/rule.py
+++ b/lib/rucio/core/rule.py
@@ -1,4 +1,5 @@
-# Copyright 2012-2020 CERN for the benefit of the ATLAS collaboration.
+# -*- coding: utf-8 -*-
+# Copyright 2012-2020 CERN
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -13,23 +14,23 @@
 # limitations under the License.
 #
 # Authors:
-# - Vincent Garonne <vgaronne@gmail.com>, 2012-2018
-# - Mario Lassnig <mario.lassnig@cern.ch>, 2013-2018
+# - Vincent Garonne <vincent.garonne@cern.ch>, 2012-2018
+# - Mario Lassnig <mario.lassnig@cern.ch>, 2013-2019
 # - Martin Barisits <martin.barisits@cern.ch>, 2013-2020
 # - Cedric Serfon <cedric.serfon@cern.ch>, 2014-2020
-# - David Cameron <d.g.cameron@gmail.com>, 2014
-# - Joaquin Bogado <jbogado@linti.unlp.edu.ar>, 2014-2018
+# - David Cameron <david.cameron@cern.ch>, 2014
+# - Joaquín Bogado <jbogado@linti.unlp.edu.ar>, 2014-2018
 # - Thomas Beermann <thomas.beermann@cern.ch>, 2014-2015
 # - Hannes Hansen <hannes.jakob.hansen@cern.ch>, 2018-2019
+# - Robert Illingworth <illingwo@fnal.gov>, 2019
 # - Andrew Lister <andrew.lister@stfc.ac.uk>, 2019
 # - Dimitrios Christidis <dimitrios.christidis@cern.ch>, 2019
-# - Brandon White <bjwhite@fnal.gov>, 2019-2020
+# - Brandon White <bjwhite@fnal.gov>, 2019
 # - Luc Goossens <luc.goossens@cern.ch>, 2020
-# - Patrick Austin, <patrick.austin@stfc.ac.uk>, 2020
+# - Eli Chadwick <eli.chadwick@stfc.ac.uk>, 2020
+# - Patrick Austin <patrick.austin@stfc.ac.uk>, 2020
 # - Benedikt Ziemons <benedikt.ziemons@cern.ch>, 2020
 # - Eric Vaandering <ewv@fnal.gov>, 2020
-#
-# PY3K COMPATIBLE
 
 from __future__ import division
 
@@ -2555,10 +2556,11 @@ def __evaluate_did_attach(eval_did, session=None):
 
         # Get immediate new child DID's
         with record_timer_block('rule.evaluate_did_attach.list_new_child_dids'):
-            new_child_dids = session.query(models.DataIdentifierAssociation).filter(
-                models.DataIdentifierAssociation.scope == eval_did.scope,
-                models.DataIdentifierAssociation.name == eval_did.name,
-                models.DataIdentifierAssociation.rule_evaluation == True).all()  # noqa
+            new_child_dids = session.query(models.DataIdentifierAssociation)\
+                .with_hint(models.DataIdentifierAssociation, "INDEX_RS_ASC(contents contents_pk)", 'oracle')\
+                .filter(models.DataIdentifierAssociation.scope == eval_did.scope,
+                        models.DataIdentifierAssociation.name == eval_did.name,
+                        models.DataIdentifierAssociation.rule_evaluation == True).all()  # noqa
 
         if new_child_dids:
             # Get all unsuspended RR from parents and eval_did


Test patch: