093a71dbd6b0cffbec6ba59306387beb0d412535
galt
  Mon Jan 25 15:13:18 2016 -0800
Fixes #16708. ORDER BY is needed for all genePreds except knownGene since the index is defined for chrom+bin key rather than simply chrom or chrom+start.  This should only add a small amount of overhead.

diff --git src/hg/hgTracks/hgTracks.c src/hg/hgTracks/hgTracks.c
index 26ac46f..7fd2b16 100644
--- src/hg/hgTracks/hgTracks.c
+++ src/hg/hgTracks/hgTracks.c
@@ -3554,31 +3554,31 @@
 	{
 	hashAdd(ktHash, row[0], NULL);
 	}
     sqlFreeResult(&sr);
     }
 setEMGeneTrack();
 if (!emGeneTable)
     errAbort("Unexpected error, emGeneTable=NULL in initVirtRegionsFromEMGeneTableExons");
 if (hIsBinned(database, emGeneTable)) // skip first bin column if any
     ++rowOffset;
 sqlSafef(query, sizeof(query), "select * from %s", emGeneTable);
 if (virtualSingleChrom())
     sqlSafefAppend(query, sizeof(query), " where chrom='%s'", chromName);
 // TODO GALT may have to change this to in-memory sorting?
 // refGene is out of order because of genbank continuous loading
-if (sameString(emGeneTable,"refGene"))
+if (!sameString(emGeneTable,"knownGene"))
     sqlSafefAppend(query, sizeof(query), " order by chrom, txStart");  
 //warn("query = [%s]", query); // DEBUG REMOVE
 sr = sqlGetResult(conn, query);
 
 char chrom[256] = "";
 int start = -1;
 int end = -1;
 char lastChrom[256] = "";
 int lastStart = -1;
 int lastEnd = -1;
 int chromSize = -1;
 char lastChromSizeChrom[256] = "";
 boolean firstTime = TRUE;
 boolean isEOF = FALSE;
 struct kce *kceList = NULL, *bestKce, *prevKce;