21a59b0cdbfd27857b51632198a981faccf91113
hiram
  Mon Apr 30 09:52:39 2018 -0700
use sqlTableExists() in hTableExists for customTrash references, more efficient refs #21330

diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c
index 32fd7db..1cc52e4 100644
--- src/hg/lib/hdb.c
+++ src/hg/lib/hdb.c
@@ -948,30 +948,37 @@
 assert(profile != NULL);
 if (tableListProfChecked == NULL)
     tableListProfChecked = hashNew(0);
 char key[512];
 safef(key, sizeof(key), "%s:%s", profile, db);
 if (hashLookup(tableListProfChecked, key) == NULL)
     {
     // first time for this profile/db
     tableListHashAdd(tableListGetDbHash(db), profile, db);
     }
 }
 
 boolean hTableExists(char *db, char *table)
 /* Return TRUE if a table exists in db. */
 {
+if (sameWord(db, CUSTOM_TRASH))
+    {
+    struct sqlConnection *conn = hAllocConn(db);
+    boolean toBeOrNotToBe = sqlTableExists(conn, table);
+    hFreeConn(&conn);
+    return toBeOrNotToBe;
+    }
 struct hash *hash = tableListGetDbHash(db);
 struct slName *tableNames = NULL, *tbl = NULL;
 char trackName[HDB_MAX_TABLE_STRING];
 char chrom[HDB_MAX_CHROM_STRING];
 if (hashFindVal(hash, "chromInfo"))
     hParseTableName(db, table, trackName, chrom);
 else
     safef(trackName, sizeof(trackName), "%s", table);
 tableNames = (struct slName *)hashFindVal(hash, trackName);
 for (tbl = tableNames;  tbl != NULL;  tbl = tbl->next)
     {
     if (sameString(table, tbl->name))
 	return TRUE;
     }
 return FALSE;