Skip to content

Commit 71f7459

Browse files
authored
Merge pull request #88 from LSSTDESC/u/rknop/objstats_view
Create an object statistics materialized view for faster searching
2 parents aff1792 + 916d2af commit 71f7459

7 files changed

Lines changed: 1077 additions & 1317 deletions

File tree

src/db.py

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,13 @@ def _cursor():
353353
if echo:
354354
FDBLogger.debug( f"Sending query\n{q.as_string()}\nwith substitutions: {subdict}" )
355355

356+
if ( cursorname is not None ) and ( ( explain is not None ) or ( analyze is not None ) ):
357+
# I haven't fully figured this out, but sometimes the server-side cursor seems
358+
# to have trouble when you try to explain
359+
FDBLogger.warning( "Turning off EXPLAIN and ANALYZE for server-side cursor." )
360+
explain = False
361+
analyze= False
362+
356363
nl = '\n'
357364
if explain:
358365
FDBLogger.debug( "Explaining..." )
@@ -1544,6 +1551,43 @@ class ProcessingVersion( DBBase ):
15441551
_tablemeta = None
15451552
_pk = [ 'id' ]
15461553

1554+
1555+
@classmethod
1556+
def get_procver( cls, processing_version, dbcon=None ):
1557+
"""Return a ProcessingVersion based on a UUID, description, or alias."""
1558+
1559+
try:
1560+
pvid = util.asUUID( processing_version )
1561+
except Exception:
1562+
pvid = None
1563+
1564+
with DBCon( dbcon, dictcursor=True ) as con:
1565+
if pvid is not None:
1566+
rows = con.execute( "SELECT * FROM processing_version WHERE id=%(pv)s", { 'pv': pvid } )
1567+
if len(rows) > 0:
1568+
if len(rows) > 1:
1569+
raise RuntimeError( "This should never happen." )
1570+
return ProcessingVersion( **(rows[0]) )
1571+
1572+
rows = con.execute( "SELECT * FROM processing_version WHERE description=%(pv)s",
1573+
{ 'pv': processing_version } )
1574+
if len(rows) > 0:
1575+
if len(rows) > 1:
1576+
raise RuntimeError( "This should never happen." )
1577+
return ProcessingVersion( **(rows[0]) )
1578+
1579+
rows = con.execute( "SELECT p.* FROM processing_version p "
1580+
"INNER JOIN processing_version_alias a ON p.id=a.procver_id "
1581+
"WHERE a.description=%(pv)s",
1582+
{ 'pv': processing_version } )
1583+
if len(rows) > 0:
1584+
if len(rows ) > 1:
1585+
raise RuntimeError( "This should never happen." )
1586+
return ProcessingVersion( **(rows[0]) )
1587+
1588+
raise ValueError( f"Unknown processing version {processing_version}" )
1589+
1590+
15471591
@classmethod
15481592
def procver_id( cls, processing_version, dbcon=None ):
15491593
"""Return the uuid of processing_version.
@@ -1578,16 +1622,9 @@ def procver_id( cls, processing_version, dbcon=None ):
15781622
return ipv
15791623
except Exception:
15801624
pass
1581-
with DBCon( dbcon ) as con:
1582-
rows, _cols = con.execute( "SELECT id FROM processing_version WHERE description=%(pv)s",
1583-
{ 'pv': processing_version } )
1584-
if len(rows) > 0:
1585-
return rows[0][0]
1586-
rows, _cols = con.execute( "SELECT procver_id FROM processing_version_alias WHERE description=%(pv)s",
1587-
{ 'pv': processing_version } )
1588-
if len(rows) == 0:
1589-
raise ValueError( f"Unknown processing version {processing_version}" )
1590-
return rows[0][0]
1625+
1626+
pv = cls.get_procver( processing_version, dbcon=dbcon )
1627+
return pv.id
15911628

15921629

15931630
def highest_prio_base_procver( self, table, dbcon=None ):

0 commit comments

Comments
 (0)