def setupTempTables(db):
    logMe(3)
    cu = db.cursor()

    # the following are specific temp tables for various functions.
    if "tmpFlavorMap" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpFlavorMap(
            flavorId    INTEGER NOT NULL,
            base        VARCHAR(254) NOT NULL,
            sense       INTEGER,
            depClass    INTEGER NOT NULL,
            flag        VARCHAR(254)
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpFlavorMap"] = True
        db.createIndex("tmpFlavorMap", "tmpFlavorMapBaseIdx", "flavorId,depClass,base",
                       check = False)
        db.createIndex("tmpFlavorMap", "tmpFlavorMapSenseIdx", "flavorId,sense",
                       check = False)
    if "tmpNewStreams" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpNewStreams(
            fileId      %(BINARY20)s,
            stream      %(MEDIUMBLOB)s,
            sha1        %(BINARY20)s
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpNewStreams"] = True
        db.createIndex("tmpNewStreams", "tmpNewStreamssFileIdx", "fileId",
                       check = False)

    if "tmpNewPaths" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpNewPaths(
            path        %(PATHTYPE)s
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpNewPaths"] = True

    if "tmpNewBasenames" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpNewBasenames(
            dir         %(PATHTYPE)s
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpNewBasenames"] = True

    if "tmpNewFiles" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpNewFiles(
            pathId      %(BINARY16)s,
            versionId   INTEGER,
            fileId      %(BINARY20)s,
            dirNameId   INTEGER,
            baseNameId  INTEGER,
            pathChanged INTEGER,
            instanceId  INTEGER
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpNewFiles"] = True
        # it sucks that we have to create this many indexes for this table;
        # that's what we get for a non-normalized reprezentation...
        db.createIndex("tmpNewFiles", "tmpNewFilesPathIdIdx", "pathId",
                       check = False)
        db.createIndex("tmpNewFiles", "tmpNewFilesFileIdx", "fileId",
                       check = False)
        db.createIndex("tmpNewFiles", "tmpNewFilesVersionIdx", "versionId",
                       check = False)
    if "tmpNewRedirects" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpNewRedirects(
            item        %(STRING)s,
            branch      %(STRING)s,
            flavor      %(STRING)s
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpNewRedirects"] = True
    if "tmpNVF" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpNVF(
            idx         %(PRIMARYKEY)s,
            name        VARCHAR(254),
            version     %(STRING)s,
            flavor      %(STRING)s
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpNVF"] = True
        db.createIndex("tmpNVF", "tmpNVFnameIdx", "name", check=False)
    if "tmpInstanceId" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpInstanceId(
            idx         INTEGER,
            instanceId  INTEGER
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpInstanceId"] = True
        db.createIndex("tmpInstanceId", "tmpInstanceIdIdx1", "idx", check=False)
        db.createIndex("tmpInstanceId", "tmpInstanceIdIdx2", "instanceId", check=False)
    if "tmpTroveInfo" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpTroveInfo(
            idx         INTEGER,
            instanceId  INTEGER,
            infoType    INTEGER,
            data        %(MEDIUMBLOB)s
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpTroveInfo"] = True
        db.createIndex("tmpTroveInfo", "tmpTIidx", "idx", check = False)
        db.createIndex("tmpTroveInfo", "tmpTIinfoTypeIdx", "infoType, instanceId", check = False)
    if "tmpFileId" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpFileId(
            itemId      %(PRIMARYKEY)s,
            fileId      %(BINARY20)s
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpFileId"] = True
        db.createIndex("tmpFileId", "tmpFileIdFileIdIdx", "fileId", check=False)
    if "tmpIVF" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpIVF(
            item        VARCHAR(254),
            version     %(STRING)s,
            fullVersion %(STRING)s
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpIVF"] = True
    if "tmpGTVL" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpGTVL(
            item        %(STRING)s,
            versionSpec %(STRING)s,
            flavorId    INTEGER
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpGTVL"] = True
        db.createIndex("tmpGTVL", "tmpGTVLitemIdx", "item", check = False)
    if "tmpFilePaths" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpFilePaths(
            row         INTEGER,
            dirname     %(PATHTYPE)s,
            basename    %(PATHTYPE)s
        )""" % db.keywords)
        db.tempTables["tmpFilePaths"] = True
        db.createIndex("tmpFilePaths", "tmpFilePathsDirnameIdx", "dirname", check=False)
    # used primarily for dependency resolution
    if "tmpInstances" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpInstances(
            instanceId    INTEGER
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpInstances"] = True
        db.createIndex("tmpInstances", "tmpInstancesIdx", "instanceId", check=False)
    # general purpose temporary lists of integers
    if "tmpId" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpId(
            id    INTEGER
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpId"] = True
        db.createIndex("tmpId", "tmpIdIdx", "id", check=False)
    # general purpose list of strings
    if "tmpItems" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpItems(
            itemId    INTEGER,
            item      %(STRING)s
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpItems"] = True
        db.createIndex("tmpItems", "tmpItemsItemIdIdx", "itemId", check=False)
        db.createIndex("tmpItems", "tmpItemsItemIdx", "item", check=False)
    # general purpose list of paths
    if "tmpPaths" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpPaths(
            id    INTEGER,
            path  %(PATHTYPE)s
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpPaths"] = True
        db.createIndex("tmpPaths", "tmpPathsIdIdx", "id", check=False)
        db.createIndex("tmpPaths", "tmpPathsPathIdx", "path", check=False)
    # for processing UserGroupInstancesCache entries
    if "tmpUGI" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpUGI(
            userGroupid   INTEGER,
            instanceId    INTEGER
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpUGI"] = True
        db.createIndex("tmpUGI", "tmpUGIIdx", "instanceId,userGroupId",
                       unique=True, check=False)
    if "tmpTroves" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpTroves(
            idx             %(PRIMARYKEY)s,
            instanceId      INTEGER NOT NULL,
            item            VARCHAR(254),
            version         %(STRING)s,
            branch          %(STRING)s,
            label           %(STRING)s,
            timestamps      %(STRING)s,
            finalTimestamp  NUMERIC(13,3) NOT NULL,
            frozenVersion   %(STRING)s,
            flavor          %(STRING)s,
            flags           INTEGER NOT NULL DEFAULT 0,
            troveType       INTEGER NOT NULL DEFAULT 0
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpTroves"] = True
        # XXX: this index helps postgresql and hurts mysql.
        #db.createIndex("tmpTroves", "tmpTrovesIdx", "item",
        #               check = False)

    if "tmpNewTroves" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpNewTroves(
            itemId        INTEGER NOT NULL,
            branchId      INTEGER NOT NULL,
            flavorId      INTEGER NOT NULL,
            versionId     INTEGER NOT NULL,
            instanceId    INTEGER NOT NULL,
            hidden        INTEGER NOT NULL,
            oldInstanceId INTEGER,
            finalTimestamp      NUMERIC(13,3) NOT NULL,
            troveType       INTEGER NOT NULL DEFAULT 0
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpNewTroves"] = True

    if "tmpNewLatest" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpNewLatest(
            userGroupId     INTEGER NOT NULL,
            itemId          INTEGER NOT NULL,
            branchId        INTEGER NOT NULL,
            flavorId        INTEGER NOT NULL,
            versionId       INTEGER NOT NULL,
            latestType      INTEGER NOT NULL
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpNewLatest"] = True

    # for processing markRemoved
    if "tmpRemovals" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpRemovals(
            instanceId      INTEGER,
            itemId          INTEGER,
            versionId       INTEGER,
            flavorId        INTEGER,
            branchId        INTEGER
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpRemovals"] = True
        db.createIndex("tmpRemovals", "tmpRemovalsInstances", "instanceId",
                       check = False)
    # for processing getDepSuggestion
    if "tmpDeps" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpDeps(
            idx         INTEGER,
            depNum      INTEGER NOT NULL,
            class       INTEGER NOT NULL,
            name        VARCHAR(254) NOT NULL,
            flag        VARCHAR(254) NOT NULL
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpDeps"] = True
        db.createIndex("tmpDeps", "tmpDepsIdx", "idx",
                       check = False)
        db.createIndex("tmpDeps", "tmpDepsClassIdx", "class",
                       check = False)
        db.createIndex("tmpDeps", "tmpDepsNameIdx", "name",
                       check = False)
    if "tmpDepNum" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpDepNum(
            idx         INTEGER NOT NULL,
            depNum      INTEGER NOT NULL,
            flagCount   INTEGER NOT NULL
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpDepNum"] = True
        db.createIndex("tmpDepNum", "tmpDepNumIdx", "idx, depNum",
                       check = False, unique=True)
    # for processing intermediary results for pathid lookups
    if "tmpPathIdLookup" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpPathIdLookup(
            versionId           INTEGER NOT NULL,
            filePathId          INTEGER NOT NULL,
            streamId            INTEGER NOT NULL,
            finalTimestamp      NUMERIC(13,3) NOT NULL
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpPathIdLookup"] = True

    if "tmpSha1s" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpSha1s(
            sha1        %(BINARY20)s
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpSha1s"] = True

    if "tmpGroupInsertShim" not in db.tempTables:
        cu.execute("""
        CREATE TEMPORARY TABLE tmpGroupInsertShim(
            itemId        INTEGER NOT NULL,
            versionId     INTEGER NOT NULL,
            flavorId      INTEGER NOT NULL,
            flags         INTEGER NOT NULL,
            instanceId    INTEGER NOT NULL
        ) %(TABLEOPTS)s""" % db.keywords)
        db.tempTables["tmpGroupInsertShim"] = True
dataset/ETHPy150Open sassoftware/conary/conary/server/schema.py/setupTempTables/original