{"id":13480801,"url":"https://github.com/sandboxws/awesome_explain","last_synced_at":"2025-03-27T11:30:57.867Z","repository":{"id":32995657,"uuid":"149036346","full_name":"sandboxws/awesome_explain","owner":"sandboxws","description":"AwesomeExplain provides the same APM's level of query analysis under your development and test Rails environments.","archived":false,"fork":false,"pushed_at":"2023-08-07T22:01:13.000Z","size":8903,"stargazers_count":16,"open_issues_count":11,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-21T12:54:27.326Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sandboxws.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-09-16T21:11:58.000Z","updated_at":"2023-09-27T21:34:50.000Z","dependencies_parsed_at":"2024-01-12T03:02:19.120Z","dependency_job_id":null,"html_url":"https://github.com/sandboxws/awesome_explain","commit_stats":{"total_commits":22,"total_committers":3,"mean_commits":7.333333333333333,"dds":"0.40909090909090906","last_synced_commit":"3583cecc76346c3d69d6793f9c0327e3c4e55514"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandboxws%2Fawesome_explain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandboxws%2Fawesome_explain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandboxws%2Fawesome_explain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandboxws%2Fawesome_explain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sandboxws","download_url":"https://codeload.github.com/sandboxws/awesome_explain/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245267510,"owners_count":20587458,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T17:00:45.172Z","updated_at":"2025-03-27T11:30:57.833Z","avatar_url":"https://github.com/sandboxws.png","language":"Ruby","funding_links":[],"categories":["Libraries"],"sub_categories":["Ruby"],"readme":"# AwesomeExplain\n\nAwesomeExplain provides the same APM's level of query analysis under your development and test Rails environments.\n\n## Main Features\n\n* A set of utilities for analyzing MongoDB and SQL queries from Rails console.\n* Tracking queries under your database of choice (SQLite3 or PostgreSQL)\nwhich can be viewed under [Athena's](https://github.com/sandboxws/athena_dashboard) dashboard.\n\n![Build Status](https://github.com/sandboxws/awesome_explain/actions/workflows/mongodb.yml/badge.svg)\n![Build Status](https://github.com/sandboxws/awesome_explain/actions/workflows/postgres.yml/badge.svg)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n## Installation\n\nAdd the following line to your application's Gemfile:\n\n`gem 'awesome_explain', require: true`\n\n## Console Utility Methods\n\n* **ae**: Prints a query's execution plan using a user friendly terminal table\n  * Currently supports the following classes:\n    * `Mongo::Collection::View::Aggregation`\n    * `Mongoid::Criteria`\n    * `ActiveRecord::Relation`\n* **analyze**: Prints a summary of all MongoDB queries passed to the Ruby block\n* **analyze_ar**: Prints a summary of all ActiveRecord queries passed to the Ruby block\n\n*Detailed usage examples can be found below.*\n\n## MongoDB\n\n### Usage\n\n`ae Article.where(author_id: '5b9ec484d5cc2e697189d7c9')`\n\n```\n+--------------------+-----------------------------+\n| Winning Plan       | FETCH (7 / 7) -\u003e IXSCAN (7) |\n+--------------------+-----------------------------+\n| Used Indexes       | author_id_1 (forward)       |\n+--------------------+-----------------------------+\n| Rejected Plans     | 0                           |\n+--------------------+-----------------------------+\n| Documents Returned | 7                           |\n+--------------------+-----------------------------+\n| Documents Examined | 7                           |\n+--------------------+-----------------------------+\n| Keys Examined      | 7                           |\n+--------------------+-----------------------------+\n| Execution time(ms) | 0                           |\n+--------------------+-----------------------------+\n| Execution time(s)  | 0.0                         |\n+--------------------+-----------------------------+\n```\n\n`ae Article.or([{author_id: '5b9ec484d5cc2e697189d7c9', state: 'published'}, {created_at: 3.days.ago}])`\n\n```\n\n+--------------------+-------------------------------------------------------------------------------------------------------------------------------------------+\n| Winning Plan       | SORT (20) -\u003e SORT_KEY_GENERATOR (20) -\u003e FETCH (24 / 20) -\u003e OR (24) -\u003e [  FETCH (24 / 24) -\u003e IXSCAN (24) ,  FETCH (0 / 0) -\u003e IXSCAN (0) ]  |\n+--------------------+-------------------------------------------------------------------------------------------------------------------------------------------+\n| Used Indexes       | state_1 (forward), author_id_1 (forward)                                                                                                  |\n+--------------------+-------------------------------------------------------------------------------------------------------------------------------------------+\n| Rejected Plans     | 18                                                                                                                                        |\n+--------------------+-------------------------------------------------------------------------------------------------------------------------------------------+\n| Documents Returned | 20                                                                                                                                        |\n+--------------------+-------------------------------------------------------------------------------------------------------------------------------------------+\n| Documents Examined | 48                                                                                                                                        |\n+--------------------+-------------------------------------------------------------------------------------------------------------------------------------------+\n| Keys Examined      | 24                                                                                                                                        |\n+--------------------+-------------------------------------------------------------------------------------------------------------------------------------------+\n| Execution time(ms) | 37                                                                                                                                        |\n+--------------------+-------------------------------------------------------------------------------------------------------------------------------------------+\n| Execution time(s)  | 0.037                                                                                                                                     |\n+--------------------+-------------------------------------------------------------------------------------------------------------------------------------------+\n```\n\n`ae Product.where(_id: 22)`\n\n```\n+--------------------+----------------+\n| Winning Plan       | IDHACK (1 / 1) |\n+--------------------+----------------+\n| Used Indexes       |                |\n+--------------------+----------------+\n| Rejected Plans     | 0              |\n+--------------------+----------------+\n| Documents Returned | 1              |\n+--------------------+----------------+\n| Documents Examined | 1              |\n+--------------------+----------------+\n| Keys Examined      | 1              |\n+--------------------+----------------+\n| Execution time(ms) | 90             |\n+--------------------+----------------+\n| Execution time(s)  | 0.09           |\n+--------------------+----------------+\n```\n\n### Winning Plan Examples\n\n`FETCH (7 / 7) -\u003e IXSCAN (7)`\n\nBelow is a breakdown of the above winning plan:\n\n- First stage is a `FETCH` stage. 7 documents were examined, and 7 were returned.\n- Second stage was an `IXSCAN` stage were 7 documents were returned.\n\nFor information about MongoDB's explain output, please refer to the official MongoDB Explain documentation:\nhttps://docs.mongodb.com/manual/reference/explain-results/\n\n## PostgreSQL\n\n### ae Usage\n\n#### Query using PK index\n\n`ae Film.where(film_id: 1)`\n\n```\n+--------------------+-------+\n|       General Stats        |\n+--------------------+-------+\n| Table              | Count |\n+--------------------+-------+\n| Total Rows Planned | 1     |\n| Total Rows         | 1     |\n| Total Loops        | 1     |\n| Seq Scans          | 0     |\n| Indexes Used       | 1     |\n+--------------------+-------+\n|        Table Stats         |\n+--------------------+-------+\n| Table              | Count |\n+--------------------+-------+\n| film               | 1     |\n+--------------------+-------+\n|      Node Type Stats       |\n+--------------------+-------+\n| Node Type          | Count |\n+--------------------+-------+\n| Index Scan         | 1     |\n+--------------------+-------+\n|        Index Stats         |\n+--------------------+-------+\n| Index Name         | Count |\n+--------------------+-------+\n| film_pkey          | 1     |\n+--------------------+-------+\n```\n\n#### Query not using any index\n\n`ae Film.where(description: 'Alien Center')`\n\n```\n+--------------------+-------+\n|       General Stats        |\n+--------------------+-------+\n| Table              | Count |\n+--------------------+-------+\n| Total Rows Planned | 1     |\n| Total Rows         | 0     |\n| Total Loops        | 1     |\n| Seq Scans          | 1     |\n| Indexes Used       | 0     |\n+--------------------+-------+\n|        Table Stats         |\n+--------------------+-------+\n| Table              | Count |\n+--------------------+-------+\n| film               | 1     |\n+--------------------+-------+\n|      Node Type Stats       |\n+--------------------+-------+\n| Node Type          | Count |\n+--------------------+-------+\n| Seq Scan           | 1     |\n+--------------------+-------+\n```\n\n### analyze_ar Usage\n\n`analyze_ar { Film.where(film_id: 1).to_a; Actor.where(last_name: 'Cage').to_a };0`\n\n```\n+--------------------+----------------+\n| Time (sec)         | 0.0            |\n+--------------------+----------------+\n| Total Rows Planned | 3              |\n+--------------------+----------------+\n| Total Rows         | 3              |\n+--------------------+----------------+\n| Total Loops        | 2              |\n+--------------------+----------------+\n| Seq Scans          | 1              |\n+--------------------+----------------+\n| Tables             | film (1)       |\n|                    | actor (1)      |\n+--------------------+----------------+\n| Node Types         | Index Scan (1) |\n|                    | Seq Scan (1)   |\n+--------------------+----------------+\n| Indexes            | film_pkey (1)  |\n+--------------------+----------------+\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/sandboxws/awesome_explain. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the AwesomeExplain project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/sandboxws/awesome_explain/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandboxws%2Fawesome_explain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsandboxws%2Fawesome_explain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandboxws%2Fawesome_explain/lists"}