当前位置: 首页 > 软件库 > 数据库相关 > >

sqlcheck

授权协议 Apache-2.0 License
开发语言 C/C++
所属分类 数据库相关
软件类型 开源软件
地区 不详
投 递 者 马欣荣
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

What Is SQLCheck?

sqlcheck automatically detects common SQL anti-patterns. Such anti-patterns often slow down queries. Addressing them will, therefore, help accelerate queries.

sqlcheck targets all major SQL dialects.

For development updates on sqlcheck and general news on next generation database systems, follow me at @joy_arulraj.

What it can do

Right now SQLCheck can detect the following anti-patterns:

Logical Database Design Anti-Patterns

Physical Database Design Anti-Patterns

Query Anti-Patterns

Application Development Anti-Patterns

Installation

UBUNTU/MINT (DEBIAN)

  1. Download the debian package from the latest release.
wget https://github.com/jarulraj/sqlcheck/releases/download/v1.2/sqlcheck-x86_64.deb
  1. Install it by running the following command.
dpkg -i sqlcheck-x86_64.deb

FEDORA/CENTOS (RPM)

  1. Download the rpm package from the latest release.
wget https://github.com/jarulraj/sqlcheck/releases/download/v1.2/sqlcheck-x86_64.rpm
  1. Install it by running the following command.
yum --nogpgcheck localinstall sqlcheck-x86_64.rpm

MAC (DMG)

  1. Download the dmg package from the latest release.
wget https://github.com/jarulraj/sqlcheck/releases/download/v1.2/sqlcheck-x86_64.dmg
  1. Click the dmg to mount the package. This will mount it in the Volumes directory.

  2. Open the Terminal app. This page contains more details on finding the app.

  3. Copy over the SQLCheck binary file to desired local directory.

cp /Volumes/sqlcheck-x86_64/bin/sqlcheck /usr/local/bin/

Homebrew

Another alternative is to use Homebrew. Here's a tap written by @gwerbin :

brew tap gwerbin/tap
brew cask install gwerbin/tap/sqlcheck

WINDOWS (EXE)

  1. Download the exe file from the latest release.
wget https://github.com/jarulraj/sqlcheck/releases/download/v1.2/sqlcheck.exe
  1. Open a terminal (like cmd.exe) and run the executable.

ZIP

  1. Download the zip package from the latest release.
wget https://github.com/jarulraj/sqlcheck/releases/download/v1.2/sqlcheck-x86_64.zip
  1. Unzip it and find the SQLCheck binary (bin/sqlcheck).
unzip sqlcheck-x86_64.zip

SOURCE CODE

SQLCheck has the following software dependencies:

First, clone the repository (with --recursive option).

git clone --recursive https://github.com/jarulraj/sqlcheck.git

Next, run the following commands to build and install SQLCheck:

./bootstrap
cd build
cmake -DCMAKE_BUILD_TYPE=RELEASE ..
make
make install

Usage

$ sqlcheck -h

Command line options : sqlcheck <options>
   -f --file_name          :  file name
   -r --risk_level         :  set of anti-patterns to check
                           :  1 (all anti-patterns, default) 
                           :  2 (only medium and high risk anti-patterns) 
                           :  3 (only high risk anti-patterns) 
   -c --color_mode         :  color mode 
   -v --verbose_mode       :  verbose mode
$ sqlcheck -f examples/top_mutexes.sql -v 

-------------------------------------------------
> RISK LEVEL    :: ALL ANTI-PATTERNS
> SQL FILE NAME :: examples/top_mutexes.sql
-------------------------------------------------
==================== Results ===================

-------------------------------------------------
SQL Statement: with top_mutexes as ( select--+ leading(t1 s1 v1 v2 t2 s2) use_hash(s1)
use_nl(v1) use_hash(s2) materialize t1.hsecs ,s1.* ,s2.sleeps as end_sleeps
,s2.wait_time as end_wait_time ,s2.sleeps-s1.sleeps as delta_sleeps ,t2.hsecs -
t1.hsecs as delta_hsecs --,s2.* from v$timer t1 ,v$mutex_sleep s1 ,(select/*+
no_merge */ sum(level) a from dual connect by level<=1e6) v1 ,v$timer t2
,v$mutex_sleep s2 where s1.mutex_type=s2.mutex_type and s1.location=s2.location
) select * from top_mutexes order by delta_sleeps desc;
[examples/top_mutexes.sql]: (HIGH RISK) (QUERY ANTI-PATTERN) SELECT *

● Inefficiency in moving data to the consumer:

When you SELECT *, you're often retrieving more columns from the database than
your application really needs to function. This causes more data to move from
the database server to the client, slowing access and increasing load on your
machines, as well as taking more time to travel across the network. This is
especially true when someone adds new columns to underlying tables that didn't
exist and weren't needed when the original consumers coded their data access.   


● Indexing issues:

Consider a scenario where you want to tune a query to a high level of
performance. If you were to use *, and it returned more columns than you
actually needed, the server would often have to perform more expensive methods
to retrieve your data than it otherwise might. For example, you wouldn't be able
to create an index which simply covered the columns in your SELECT list, and
even if you did (including all columns [shudder]), the next developer who came around
and added a column to the underlying table would cause the optimizer to ignore
your optimized covering index, and you'd likely find that the performance of
your query would drop substantially for no readily apparent reason.    
[Matching Expression: select *]

[examples/top_mutexes.sql]: (LOW RISK) (QUERY ANTI-PATTERN) Spaghetti Query Alert   

● Split up a complex spaghetti query into several simpler queries:

SQL is a very expressive language—you can accomplish a lot in a single query
or statement. But that doesn't mean it's mandatory or even a good idea to
approach every task with the assumption it has to be done in one line of code.
One common unintended consequence of producing all your results in one query is
a Cartesian product. This happens when two of the tables in the query have no
condition restricting their relationship. Without such a restriction, the join
of two tables pairs each row in the first table to every row in the other table.
Each such pairing becomes a row of the result set, and you end up with many more
rows than you expect. 

It's important to consider that these queries are simply
hard to write, hard to modify, and hard to debug. You should expect to get
regular requests for incremental enhancements to your database applications.
Managers want more complex reports and more fields in a user interface. If you
design intricate, monolithic SQL queries, it's more costly and time-consuming to
make enhancements to them. Your time is worth something, both to you and to your
project. Split up a complex spaghetti query into several simpler queries. When
you split up a complex SQL query, the result may be many similar queries,
perhaps varying slightly depending on data values. Writing these queries is a
chore, so it's a good application of SQL code generation. Although SQL makes it
seem possible to solve a complex problem in a single line of code, don't be
tempted to build a house of cards.   

==================== Summary ===================   
All Anti-Patterns  :: 2   
>  High Risk   :: 1   
>  Medium Risk :: 0   
>  Low Risk    :: 1   

References

(1) SQL Anti-patterns: Avoiding the Pitfalls of Database Programming, Bill Karwin
(2) Common SQL Anti-patterns, StackOverflow

Contributions

Contributions to SQLCheck are always welcome. You can contribute in different ways:

  • Open an issue with suggestions for improvements and errors you're facing;
  • Fork this repository and submit a pull request;
  • Improve the documentation.

License

Licensed under the Apache License.

  • 参考源 简单教程 https://www.twle.cn/l/yufei/sql/sql-basic-check.html 菜鸟教程 https://www.runoob.com/sql/sql-check.html SQL check 约束 SQL check 约束用于限制列中的值的范围 check 约束既可以用于某一列也可以用于某张表: 如果对单个列定义 CHECK 约束,那么该列只允许特定的

  • CHECK约束会: 检查输入到记录中的值是否满足一个条件,如果不满足这个条件则对数据库做的修改不会成功。 如,一个人的年龄是不可能为负数的,一个人的入学日期不可能早于出生日期,出厂月份不可能大于12。可以在CHECK条件中使用任意有效的SQL表达式,CHECK约束对于插入、更新等任何对数据进行变化的操作都进行检查。 字段添加CHECK约束:在该字段定义后添加CHECK 表达式,几乎所有字段中都可以

  • SQL CHECK约束 一、 说明 本文主要讲一下SQL的CHECK约束有关的内容。 二、 所用工具 SQL 数据库 三、 内容 1.CHECK 约束说明 用于限制列中的值的范围。如果对单个列定义 CHECK 约束,那么该列只允许特定的值。 2.添加CHECK 约束: (1)在添加表时添加CHECK约束: 语法: CREATE TABLE Persons (列名 数据类型及长度 约束, 列名 数据

  • SQL CHECK 约束 CHECK 约束用于限制列中的值得范围。 如果对单个定于的CHECK 约束,那么该列只允许特定的值。 如果对一个表定于CHECK 约束,那么此约束会基于行中其他列的值在特定的列中对值进行限制。 CREATE TABLE 时的SQL CHECK 约束 下面的SQL 在"Persons"表创建CHECK 约束。CHECK 约束规定"p_id"列必须只包含大于0的整数。 CRE

  • sql check约束 Basically, CHECK constraint is used to LIMIT in columns for the range of values. We can use this constraint for single or multiple columns. 基本上, CHECK约束用于限制值范围内的列 。 我们可以将此约束用于单列或多列。 In sin

  • SQL学习 学习SQL语法 SQL语法之 CHECK 约束 CHECK 约束用于限制列中的值的范围。 如果对单个列定义 CHECK 约束,那么该列只允许特定的值。 如果对一个表定义 CHECK 约束,那么此约束会在特定的列中对值进行限制。 SQL CHECK Constraint on CREATE TABLE 下面的 SQL 在 “Persons” 表创建时为 “Id_P” 列创建 CHECK

  • SQL-CHECK约束 SQL-CHECK检查约束实例代码教程 - 条件检查被输入的值。如果条件计算为false,记录中的列的值违反了约束,从而不能写入到表中。 CHECK约束,条件检查被输入的值。如果条件计算为false,记录中的列的值违反了约束,从而不能写入到表中。 实例: 例如,下面的SQL语句创建一个新的表名为CUSTOMERS,并增加了5列。随着年龄的增长列在这里,我们添加了一个查看,这

  • SQL中的CHECK约束的详细讲解 CHECK 约束(CHECK 约束:定义列中可接受的数据值。可以将 CHECK 约束应用于多个列,也可以将多个 CHECK 约束应用于单个列。当除去某个表时,也将除去 CHECK 约束。)指定可由表中一列或多列接受的数据值或格式。例如,可以要求 authors 表的 zip 列只允许输入五位数的数字项。      可以为一个表定义许多 CHECK 约束。可以使用

  • sql之check约束 简介 check主要用于限定字段值的范围 常见用法举例 重量需大于0,并且小于等于100 WEIGHT NUMERIC(9,2) CHECK(WEIGHT>0 AND WEIGHT<=100 性别取‘男’或者‘女’ SSEX CHAR(2) CHECK(SSEX='male' OR SSEX='female') 年龄取15-45 SAGE SMALLINT CHECK(

  • SQL CHECK 约束 CHECK 约束用于限制列中的值的范围。 如果对单个列定义 CHECK 约束,那么该列只允许特定的值。 如果对一个表定义 CHECK 约束,那么此约束会基于行中其他列的值在特定的列中对值进行限制。 CREATE TABLE 时的 SQL CHECK 约束 下面的 SQL 在 “Persons” 表创建时在 “P_Id” 列上创建 CHECK 约束。CHECK 约束规定 “

相关阅读

相关文章

相关问答

相关文档