gorm_explain

package module
v0.0.0-...-f6ec771 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2017 License: MIT Imports: 5 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

gorm-explain

extension library of gorm. explain log output.

Usage

db, _ := gorm.Open("mysql", buildDataSourceName(opts))
defer db.Close()
db.Callback().Query().Register("explain", gorm_explain.Callback) // Add Callback 

Example

example code

Output Sample

$ go run main.go
(/Users/kyokomi/workspace/go/src/github.com/kyokomi/gorm-explain/example/main.go:53) 
[2017-05-05 18:15:44]  [1.02ms]  INSERT INTO `products` (`created_at`,`updated_at`,`deleted_at`,`code`,`price`) VALUES ('2017-05-05 18:15:44','2017-05-05 18:15:44',NULL,'L1212','1000')

(/Users/kyokomi/workspace/go/src/github.com/kyokomi/gorm-explain/example/main.go:57) 
[2017-05-05 18:15:44]  [1.25ms]  SELECT * FROM `products`  WHERE `products`.`deleted_at` IS NULL AND ((`products`.`id` = '1')) ORDER BY `products`.`id` ASC LIMIT 1
+-------+----------------+----------+---------------+---------+------------------+--------+------------+--------+---------+-------------+--------------------------------------------------------+
|    id |    select_type |    table |    partitions |    type |    possible_keys |    key |    key_len |    ref |    rows |    filtered |                                                  Extra |
+=======+================+==========+===============+=========+==================+========+============+========+=========+=============+========================================================+
|     1 |         SIMPLE |          |               |         |                  |        |            |        |         |             |    Impossible WHERE noticed after reading const tables |
+-------+----------------+----------+---------------+---------+------------------+--------+------------+--------+---------+-------------+--------------------------------------------------------+


(/Users/kyokomi/workspace/go/src/github.com/kyokomi/gorm-explain/example/main.go:58) 
[2017-05-05 18:15:44]  [1.67ms]  SELECT * FROM `products`  WHERE `products`.`deleted_at` IS NULL AND ((code = 'L1212')) ORDER BY `products`.`id` ASC LIMIT 1
+-------+----------------+-------------+---------------+---------+----------------------------+----------------------------+------------+----------+---------+-------------+---------------------------------------+
|    id |    select_type |       table |    partitions |    type |              possible_keys |                        key |    key_len |      ref |    rows |    filtered |                                 Extra |
+=======+================+=============+===============+=========+============================+============================+============+==========+=========+=============+=======================================+
|     1 |         SIMPLE |    products |               |     ref |    idx_products_deleted_at |    idx_products_deleted_at |          5 |    const |       1 |         100 |    Using index condition; Using where |
+-------+----------------+-------------+---------------+---------+----------------------------+----------------------------+------------+----------+---------+-------------+---------------------------------------+


(/Users/kyokomi/workspace/go/src/github.com/kyokomi/gorm-explain/example/main.go:61) 
[2017-05-05 18:15:44]  [0.90ms]  UPDATE `products` SET `price` = '2000', `updated_at` = '2017-05-05 18:15:44'  WHERE `products`.`deleted_at` IS NULL AND `products`.`id` = '6'

(/Users/kyokomi/workspace/go/src/github.com/kyokomi/gorm-explain/example/main.go:64) 
[2017-05-05 18:15:44]  [1.27ms]  UPDATE `products` SET `deleted_at`='2017-05-05 18:15:44'  WHERE `products`.`deleted_at` IS NULL AND `products`.`id` = '6'

Support Driver

  • mysql

Requirement

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Callback

func Callback(scope *gorm.Scope)

Callback output explain callback

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址