query

package
v0.0.0-...-3eaa125 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2022 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package query provides functions to transform queries.

Index

Examples

Constants

This section is empty.

Variables

View Source
var Debug bool = false

Debug prints very verbose tracing information to STDOUT.

View Source
var ReplaceNumbersInWords = false

ReplaceNumbersInWords enables replacing numbers in words. For example: `SELECT c FROM org235.t` -> `SELECT c FROM org?.t`. For more examples look at test query_test.go/TestFingerprintWithNumberInDbName.

Functions

func Fingerprint

func Fingerprint(q string) string

Fingerprint returns the canonical form of q. The primary transformations are:

  • Replace values with ?
  • Collapse whitespace
  • Remove comments
  • Lowercase everything

Additional trasnformations are performed which change the syntax of the original query without affecting its performance characteristics. For example, "ORDER BY col ASC" is the same as "ORDER BY col", so "ASC" in the fingerprint is removed.

Example
package main

import (
	"fmt"

	"github.com/percona/go-mysql/query"
)

func main() {
	q := "SELECT c FROM t WHERE a=1 AND b='foo'\n" +
		"/* some comment */ ORDER BY c ASC LIMIT 1"
	f := query.Fingerprint(q)
	fmt.Println(f)
}
Output:

func Id

func Id(fingerprint string) string

Id returns the right-most 16 characters of the MD5 checksum of fingerprint. Query IDs are the shortest way to uniquely identify queries.

Types

This section is empty.

Jump to

Keyboard shortcuts

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