After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 615429 - Optimize global and local views sql queries
Optimize global and local views sql queries
Status: RESOLVED OBSOLETE
Product: anjuta
Classification: Applications
Component: plugins: symbol-db
git master
Other Linux
: Normal normal
: ---
Assigned To: Massimo Cora'
Anjuta maintainers
Depends on: 615403 615428
Blocks:
 
 
Reported: 2010-04-11 09:42 UTC by Naba Kumar
Modified: 2020-11-06 20:21 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Naba Kumar 2010-04-11 09:42:58 UTC
See http://git.gnome.org/browse/anjuta/tree/plugins/symbol-db/symbol-db-model-project.c and http://git.gnome.org/browse/anjuta/tree/plugins/symbol-db/symbol-db-model-file.c . Optimize the following sql statement used in there:

Global view:

#define SDB_MODEL_PROJECT_SQL " \
    SELECT \
        symbol.symbol_id, \
        symbol.name, \
        symbol.file_position, \
        symbol.scope_definition_id, \
        symbol.signature, \
        symbol.returntype, \
        file.file_path, \
        sym_access.access_name, \
        sym_type.type_type, \
        sym_type.type_name, \
        (symbol.kind_id IN \
        ( \
            SELECT sym_kind_id \
            FROM sym_kind \
            WHERE kind_name IN ('class', 'namespace', 'enum', 'struct', 'union') \
        )) AS has_child \
    FROM symbol \
    LEFT JOIN file ON symbol.file_defined_id = file.file_id \
    LEFT JOIN sym_access ON symbol.access_kind_id = sym_access.access_kind_id \
    LEFT JOIN sym_type ON symbol.type_id = sym_type.type_id \
    WHERE \
    ( \
        symbol.scope_id = ## /* name:'parent' type:gint */ \
        AND symbol.kind_id IN \
        ( \
            SELECT sym_kind_id \
            FROM sym_kind \
            WHERE \
            ( \
                0 = ## /* name:'parent' type:gint */ \
                AND sym_kind.kind_name IN ('class', 'struct', 'union', 'enum') \
            ) \
            OR \
            ( \
                0 != ## /* name:'parent' type:gint */ \
                AND sym_kind.kind_name != 'namespace' \
            ) \
        ) \
    ) \
    OR \
    ( \
        symbol.symbol_id IN \
        ( \
            SELECT symbol_id \
            FROM symbol \
            WHERE \
                symbol.scope_id = ## /* name:'parent' type:gint */ \
                AND symbol.kind_id IN \
                ( \
                    SELECT sym_kind_id \
                    FROM sym_kind \
                    WHERE sym_kind.kind_name = 'namespace' \
                ) \
            GROUP BY symbol.scope_definition_id \
            \
        ) \
    ) \
    ORDER BY symbol.name \
    LIMIT ## /* name:'limit' type:gint */ \
    OFFSET ## /* name:'offset' type:gint */ \
    "


Local view:

#define SDB_MODEL_FILE_SQL " \
    SELECT \
        symbol.symbol_id, \
        symbol.name, \
        symbol.file_position, \
        symbol.scope_definition_id, \
        symbol.signature, \
        symbol.returntype, \
        file.file_path, \
        sym_access.access_name, \
        sym_type.type_type, \
        sym_type.type_name, \
        (symbol.kind_id IN \
        ( \
            SELECT sym_kind_id \
            FROM sym_kind \
            WHERE kind_name IN ('class', 'namespace', 'enum', 'struct', 'union') \
        )) AS has_child \
    FROM symbol \
    LEFT JOIN file ON symbol.file_defined_id = file.file_id \
    LEFT JOIN sym_access ON symbol.access_kind_id = sym_access.access_kind_id \
    LEFT JOIN sym_type ON symbol.type_id = sym_type.type_id \
    WHERE \
    ( \
        file.file_path = ## /* name:'filepath' type:gchararray */ \
        AND symbol.scope_id = ## /* name:'parent' type:gint */ \
        AND symbol.kind_id NOT IN \
        ( \
            SELECT sym_kind_id \
            FROM sym_kind \
            WHERE sym_kind.kind_name = 'namespace' \
        ) \
    ) \
    OR \
    ( \
        symbol.symbol_id IN \
        ( \
            SELECT symbol_id \
            FROM symbol \
            LEFT JOIN file ON symbol.file_defined_id = file.file_id \
            WHERE \
                file.file_path = ## /* name:'filepath' type:gchararray */ \
                AND symbol.scope_id = ## /* name:'parent' type:gint */ \
                AND symbol.kind_id IN \
                ( \
                    SELECT sym_kind_id \
                    FROM sym_kind \
                    WHERE sym_kind.kind_name = 'namespace' \
                ) \
            GROUP BY symbol.scope_definition_id \
            \
        ) \
    ) \
    OR \
    ( \
        symbol.scope_id = ## /* name:'parent' type:gint */ \
        AND symbol.kind_id NOT IN \
        ( \
            SELECT sym_kind_id \
            FROM sym_kind \
            WHERE sym_kind.kind_name = 'namespace' \
        ) \
        AND symbol.scope_definition_id IN \
        ( \
            SELECT scope_id \
            FROM symbol \
            JOIN file ON symbol.file_defined_id = file.file_id \
            WHERE file.file_path = ## /* name:'filepath' type:gchararray */ \
            GROUP BY symbol.scope_id \
        ) \
    ) \
    ORDER BY symbol.file_position \
    LIMIT ## /* name:'limit' type:gint */ \
    OFFSET ## /* name:'offset' type:gint */ \
    "

Following optimizations can be possible:

1) Get rid of namespace hacks. The last OR expressions in both statements, and various select sub-queries involving kind = 'namespace' are the hacks to remove. This depends on bug 615403 .

2) Get rid of first select sub-query by introducing a new column 'has_child' in sym_kind table. This depends on bug 615428 .

3) See if we are missing any index in above WHERE clauses, or if we are utilizing existing indexes optimally.
Comment 1 Naba Kumar 2010-04-11 09:44:40 UTC
Set dependencies.
Comment 2 Naba Kumar 2010-05-06 19:26:55 UTC
(In reply to comment #0)
> 
> 2) Get rid of first select sub-query by introducing a new column 'has_child' in
> sym_kind table. This depends on bug 615428 .
> 
This part is fixed with http://git.gnome.org/browse/anjuta/commit/?id=29ac0d1298ab86344512e8d4e7e18a2f1411ea8b
Comment 3 André Klapper 2020-11-06 20:21:54 UTC
bugzilla.gnome.org is being replaced by gitlab.gnome.org. We are closing all old bug reports in Bugzilla which have not seen updates for many years.

If you can still reproduce this issue in a currently supported version of GNOME (currently that would be 3.38), then please feel free to report it at https://gitlab.gnome.org/GNOME/anjuta/-/issues/

Thank you for reporting this issue and we are sorry it could not be fixed.