2f262ebebd76067ea983cfeb7454ed626a450c61 angie Fri Jan 6 15:45:54 2017 -0800 In mysql 5.7 with the default configuration, it is now an error if a SELECT list using DISTINCT does not include all ORDER BY fields. The solution is to add the ORDER BY fields to the end of the SELECT list if they're not already included. The extra columns returned by the query are ignored. refs #18626, #18597 diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c index 358e252..2a89571 100644 --- src/hg/lib/hdb.c +++ src/hg/lib/hdb.c @@ -4398,59 +4398,64 @@ struct dbDb *hGetIndexedDatabasesForClade(char *db) /* Get list of active databases in db's clade. * Dispose of this with dbDbFreeList. */ { return hGetIndexedDbsMaybeClade(db); } struct slPair *hGetCladeOptions() /* Return a list of slPairs, each containing clade menu value (hgcentral.clade.name, e.g. 'mammal') * and clade menu label (hgcentral.clade.label, e.g. 'Mammal'), * useful for constructing a clade menu. */ { // get only the clades that have actual active genomes char *query = NOSQLINJ "" "SELECT DISTINCT(c.name), c.label " + // mysql 5.7: SELECT list w/DISTINCT must include all fields in ORDER BY list (#18626) + ", c.priority " "FROM %s c, %s g, %s d " "WHERE c.name=g.clade AND d.organism=g.genome AND d.active=1 " "ORDER BY c.priority"; char queryBuf[4096]; safef(queryBuf, sizeof queryBuf, query, cladeTable(), genomeCladeTable(), dbDbTable()); struct sqlConnection *conn = hConnectCentral(); struct slPair *nativeClades = sqlQuickPairList(conn, queryBuf); hDisconnectCentral(&conn); struct slPair *trackHubClades = trackHubGetCladeLabels(); return slCat(nativeClades, trackHubClades); } struct slPair *hGetGenomeOptionsForClade(char *clade) /* Return a list of slPairs, each containing genome menu value and menu label, * useful for constructing a genome menu for the given clade. */ { struct slPair *pairList = NULL; if (isHubTrack(clade)) { struct dbDb *hubDbDbList = trackHubGetDbDbs(clade), *dbDb; for (dbDb = hubDbDbList; dbDb != NULL; dbDb = dbDb->next) slAddHead(&pairList, slPairNew(dbDb->genome, cloneString(dbDb->genome))); } else { struct dyString *dy = - sqlDyStringCreate("select distinct(d.genome) from %s d,%s g " + sqlDyStringCreate("select distinct(d.genome) " + // mysql 5.7: SELECT list w/DISTINCT must include all fields in ORDER BY list (#18626) + ", orderKey " + "from %s d,%s g " "where d.genome=g.genome and g.clade = '%s' " "order by orderKey", dbDbTable(), genomeCladeTable(), clade); // Although clade and db menus have distinct values vs. labels, we actually use the // same strings for values and labels in the genome menu! So we get a plain list // from the query and turn it into a pair list. struct sqlConnection *conn = hConnectCentral(); struct slName *nativeGenomes = sqlQuickList(conn, dy->string), *g; hDisconnectCentral(&conn); dyStringFree(&dy); for (g = nativeGenomes; g != NULL; g = g->next) slAddHead(&pairList, slPairNew(g->name, cloneString(g->name))); } slReverse(&pairList); return pairList; }