`

读Effective Mysql:optimizing SQL Statements 笔记

 
阅读更多
http://effectivemysql.com/downloads/words 获取数据源
CREATE CHEMA IF NOT EXISTS book;
use book;
CREATE TABLE source_words(
  word VARCHAR(50) NOT NULL;
  index (word)
) ENGINE = MyISAM;
LOAD DATA LOCAL INFILE '/usr/share/dict/words'
INTO TABLE source_words(word);
CREATE TABLE million_words(
   id INT UNSIGNED NOT NULL AUTO_INCREMENT;
   word VARCHAR(50) NOT NULL;
   PRIMARY KEY (id),
   UNIQUE INDEX(word);
) ENGINE=InnoDB;
INSERT INTO million_words(word)
SELECT DISTINCT word FROM source_words;
INSERT INTO million_words(word)
SELECT DISTINCT REVERSE(word) FROM source_words
WHERE REVERSE(word) NOT IN (SELECT word FROM source_words);
SELECT @cint := COUNT(*) FROM million_words;
SELECT @diff :=1000000 - @cnt;
-- We need to run dynamic SQL to support a variable LIMIT
SET @sql = CONCAT("
INSERT INTO million_words(word)
SELECT DISTINCT CONCAT(word,'X1Y') FROM source_words LIMIT ",@diff);
PREPARE cmd FROM @sql;
EXECUTE cmd;
SELECT COUNT(*) FROM million_words;
分享到:
评论

相关推荐

    8.2 Optimizing SQL Statements

    为了提高应用性能,尤其是MySQL数据库应用,优化SQL语句显得至关重要。本部分将深入探讨如何优化各种SQL语句,包括数据的读写操作、SQL操作的幕后开销以及数据库监控等特定场景中的操作。 首先,我们来看如何优化...

    信息安全_数据安全_Automation_vs_Human_Eyes:Optimizing_Hu.pdf

    信息安全_数据安全_Automation_vs_Human_Eyes:Optimizing_Hu 边界防御 应用审计 web安全 云安全 用户隐私

    Energy Hub Integration: Optimizing Electricity and Heat Market P

    本文《Participation_of_an_Energy_Hub_in_Electricity_and_Heat_Distribution_Markets》深入探讨了能源枢纽在电力和热力分配市场中的参与方式。文章分析了能源枢纽如何通过集成多种能源转换技术,实现对电力和热力...

    操作系统—线程: Optimizing threaded MPI execution on SMP

    ### 操作系统—线程:优化SMP上基于线程的MPI执行 #### 摘要与背景 本文深入探讨了在共享内存多处理器(SMP)集群上使用线程来执行消息传递接口(MPI)程序的方法,并研究了其设计与实现。作者通过实验证明,在多...

    Shaping the Glitch Optimizing Voltage Fault Injection Attacks.pdf

    在“Shaping the Glitch: Optimizing Voltage Fault Injection Attacks”这篇论文中,作者Claudio Bozzato、Riccardo Focardi和Francesco Palmarini提出了一种新的电压故障注入技术,利用现成且低成本的设备生成完全...

    Top 10 Tips for Optimizing SQL Server Performance

    ### SQL Server性能优化十大技巧详解 #### 引言 在SQL Server环境中实现高效稳定的性能是一项挑战性的任务。尽管关于性能优化的一般性建议随处可见,但针对特定问题的深入指导及如何将这些知识应用到实际环境中的...

    《Pro Oracle SQL》Chapter10 -- 10.2 Optimizing SQL -10.2.1Testing Execution Plans

    《Pro Oracle SQL》一书的第10章深入探讨了SQL优化,特别是10.2节,重点关注如何测试执行计划,这是SQL性能调优的关键环节。在这个部分,作者旨在帮助读者理解如何有效地评估和改进SQL查询的性能,以提高数据库系统...

    MySql存储过程编程.chm

    Performing Dynamic SQL with Prepared Statements Section 5.6. Handling SQL Errors: A Preview Section 5.7. Conclusion Chapter 6. Error Handling Section 6.1. Introduction to Error Handling ...

    PGWinFunc: Optimizing Window Aggregate Functions in PostgreSQL and its application for trajectory data

    在研究论文《PGWinFunc: Optimizing Window Aggregate Functions in PostgreSQL and its application for trajectory data》中,重点介绍了如何在PostgreSQL数据库中优化窗口聚合函数,并展示了其在轨迹数据分析方面...

    Mysql利用profiles来查看SQL语句执行计划.doc

    MySQL 的 `Profiles` 功能是一个非常强大的工具,它允许数据库管理员和开发者深入了解 SQL 语句的执行过程,从而优化数据库性能。这一特性自 MySQL 5.0.37 版本引入,为用户提供了比 `EXPLAIN` 更深入的洞察,包括 ...

    Beginning Microsoft SQL Server 2008 Administration.pdf

    11. **第十一章:Optimizing SQL Server** - 分析SQL Server 2008性能优化的各种技术,如查询优化、索引管理等。 12. **第十二章:SQL Server High Availability** - 介绍高可用性的概念和技术,如故障转移集群、...

    Exam 70-445 微软认证考试教材

    Designing a Database Server Infrastructure by Using Microsoft SQL Server 2005 70-444 PRO: Optimizing and Maintaining a Database Administration Solution by Using Microsoft SQL Server 2005 70-...

    Collective

    在IT行业中,"Collective"这个词常常用于描述一个集合体或者整合了多种资源或元素的项目。在这里,它可能指的是一个包含多种字体资源的集合。让我们深入探讨一下关于字体的知识,以及如何管理和使用这样的集合。...

    Exam 70-441 微软认证考试教材

    Designing a Database Server Infrastructure by Using Microsoft SQL Server 2005 70-444 PRO: Optimizing and Maintaining a Database Administration Solution by Using Microsoft SQL Server 2005 70-445...

    Oracle Database 10g PL-SQL Programming

    - **Subprograms**: Introduction to procedures and functions, which can be called from other PL/SQL blocks or SQL statements. #### 2. Using SQL*Plus and JDeveloper This chapter focuses on the tools ...

    Guide to Optimizing Performance of the MySQL Cluster Database

    This guide explores how to tune and optimize the MySQL Cluster database to handle diverse workload requirements. It discusses data access patterns and how to build distribution awareness into ...

    MySQL 8 Administrator’s Guide

    Topics such as migrating to MySQL 8, MySQL benchmarking, achieving high performance by implementing the indexing techniques, and optimizing your queries are covered in this book. You will also learn ...

    Fractal Prefetching B+ Trees - Optimizing Both Cache and Disk Performance-计算机科学

    Optimizing Both Cache and Disk PerformanceShimin Chen, Phillip B. Gibbons�, Todd C. Mowry, and Gary Valentin�School of Computer Science �Information Sciences Research Center �DB2 UDB Development ...

    Microsoft SQL Server 2016: A Beginner’s Guide, 6th Edition

    From there, you will learn how to write Transact-SQL statements, execute simple and complex database queries, handle system administration and security, and use the powerful analysis and BI tools....

Global site tag (gtag.js) - Google Analytics