在海量数据中创建高效SQL笔记
在海量数据中创建高效SQL笔记 参加了郑保卫博士的讲座,收获颇多。 以前总是写一些简单的sql,以为sql只是简单的命令,实际上sql大有可为,sql是体现技术人员能力的重要方面,sql是应用程序不是查询语言!以下简单总结了昨天培训的收获: www.2cto.com 1.SQL
在海量数据中创建高效SQL笔记
参加了郑保卫博士的讲座,收获颇多。 以前总是写一些简单的sql,以为sql只是简单的命令,实际上sql大有可为,sql是体现技术人员能力的重要方面,sql是应用程序不是查询语言!以下简单总结了昨天培训的收获:
www.2cto.com
1.SQL语句是一种集合语言,而JAVA /c++甚至于PL/SQL是过程化语言,SQL语句按block处理数据,过程化语言按条处理,效率差距可想而知。
2.扩张性的SQL语句可以做所有的有关数据处理的功能,不要再将SQL语句只当做一个数据库命令,“他是巨人,不是普通人”。
3.索引非常重要,建立战略性的索引是很困难的,最好建立联合索引,除非是主键,最好不要建立单独索引。索引的建立不是越多越好,也不是越少越好,应该有一个平衡点。因为索引也需要耗费存储空间,在delete/update特别是insert的时候过于臃肿的索引会影响语句的执行效率。
4.执行计划非常重要,要有执行计划和优化器的概念,对于一个SQL语句,要能够大概判断其执行的路径是什么。
www.2cto.com
5.执行速度很大程度上和IO有关,因为CPU的计算速度已经很快了,但I/O是很大的瓶颈。所以正在研究的有“内存数据库”的概念。
6.重视统计信息的作用,优化器是根据统计信息来进行执行计划的选择和优化的,统计信息可以定时让数据库收集、也可以在大量修改数据后手工执行统计信息的更新。
7.新的优化器是基于成本的,不是基于规则的。
8.调整数据库参数能解决10%的性能问题,修改执行计划可以解决30%,建立战略性索引和优化SQL语句可以解决50%的问题,而良好的数据模型和建模可以解决80%的性能问题。
9.执行计划是非常敏感的,微小的改动可能都会改变执行计划,比如SQL语句中表连接的数据、更新的统计信息、索引的改变等。
10.离散度的好坏决定索引效果的好坏,一般认为,如果某列数据的离散度低于10%-15%时,索引是有效的。
在SQL语句where查询条件中,有的条件用户驱动查询条件、有的用于过滤查询条件。最理想的方法是将拥有最小数据范围的条件作为查询驱动条件。
11.组合索引中列的顺序有可能决定查询效率。
12.索引的使用会受到表的联系方法和联系顺序的影响的。
13.PL/SQL中判断是否存在的替换方案:
原SQL:SELECT COUNT(*) INTO :CNT
FROM ITEM_TAB
WHERE DEPT = ‘101’
AND SEQ > 100;
…………………………………………
www.2cto.com
IF CNT > 0 ….
改进后:SELECT 1 INTO :CNT FROM DUAL
WHERE EXISTS (SELECT ‘X’
FROM ITEM_TAB
WHERE DEPT = ’101’
AND SEQ > 100 );
……………………………………………
IF CNT > 0 ….
14.取最大流水号的替代方案
原SQL:SELECT MAX(seq) + 1
FROM order
WHERE deptno = ‘12300’
替代SQL:SELECT /*+ INDEX_DESC(order pk_order) */
NVL(MAX(seq), 0) + 1
FROM order
WHERE deptno = ‘12300’
AND ROWNUM = 1
www.2cto.com
15.综合原理和总结
1) 数据处理就是集合运算;
2) 要从流程开发人员转变为数据开发人员,使用复杂的SQL,复杂的执行计划来替代过程化的程序执行,可以有效的降低计算次数,配合战略性索引,可以精简代码,提到性能。
3) SQL并非命令语句,而是应用程序!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



HQL and SQL are compared in the Hibernate framework: HQL (1. Object-oriented syntax, 2. Database-independent queries, 3. Type safety), while SQL directly operates the database (1. Database-independent standards, 2. Complex executable queries and data manipulation).

0.What does this article do? We propose DepthFM: a versatile and fast state-of-the-art generative monocular depth estimation model. In addition to traditional depth estimation tasks, DepthFM also demonstrates state-of-the-art capabilities in downstream tasks such as depth inpainting. DepthFM is efficient and can synthesize depth maps within a few inference steps. Let’s read about this work together ~ 1. Paper information title: DepthFM: FastMonocularDepthEstimationwithFlowMatching Author: MingGui, JohannesS.Fischer, UlrichPrestel, PingchuanMa, Dmytr

The performance of JAX, promoted by Google, has surpassed that of Pytorch and TensorFlow in recent benchmark tests, ranking first in 7 indicators. And the test was not done on the TPU with the best JAX performance. Although among developers, Pytorch is still more popular than Tensorflow. But in the future, perhaps more large models will be trained and run based on the JAX platform. Models Recently, the Keras team benchmarked three backends (TensorFlow, JAX, PyTorch) with the native PyTorch implementation and Keras2 with TensorFlow. First, they select a set of mainstream

Facing lag, slow mobile data connection on iPhone? Typically, the strength of cellular internet on your phone depends on several factors such as region, cellular network type, roaming type, etc. There are some things you can do to get a faster, more reliable cellular Internet connection. Fix 1 – Force Restart iPhone Sometimes, force restarting your device just resets a lot of things, including the cellular connection. Step 1 – Just press the volume up key once and release. Next, press the Volume Down key and release it again. Step 2 – The next part of the process is to hold the button on the right side. Let the iPhone finish restarting. Enable cellular data and check network speed. Check again Fix 2 – Change data mode While 5G offers better network speeds, it works better when the signal is weaker

Title: Realme Phone Beginner’s Guide: How to Create Folders on Realme Phone? In today's society, mobile phones have become an indispensable tool in people's lives. As a popular smartphone brand, Realme Phone is loved by users for its simple and practical operating system. In the process of using Realme phones, many people may encounter situations where they need to organize files and applications on their phones, and creating folders is an effective way. This article will introduce how to create folders on Realme phones to help users better manage their phone content. No.

I cry to death. The world is madly building big models. The data on the Internet is not enough. It is not enough at all. The training model looks like "The Hunger Games", and AI researchers around the world are worrying about how to feed these data voracious eaters. This problem is particularly prominent in multi-modal tasks. At a time when nothing could be done, a start-up team from the Department of Renmin University of China used its own new model to become the first in China to make "model-generated data feed itself" a reality. Moreover, it is a two-pronged approach on the understanding side and the generation side. Both sides can generate high-quality, multi-modal new data and provide data feedback to the model itself. What is a model? Awaker 1.0, a large multi-modal model that just appeared on the Zhongguancun Forum. Who is the team? Sophon engine. Founded by Gao Yizhao, a doctoral student at Renmin University’s Hillhouse School of Artificial Intelligence.

The latest video of Tesla's robot Optimus is released, and it can already work in the factory. At normal speed, it sorts batteries (Tesla's 4680 batteries) like this: The official also released what it looks like at 20x speed - on a small "workstation", picking and picking and picking: This time it is released One of the highlights of the video is that Optimus completes this work in the factory, completely autonomously, without human intervention throughout the process. And from the perspective of Optimus, it can also pick up and place the crooked battery, focusing on automatic error correction: Regarding Optimus's hand, NVIDIA scientist Jim Fan gave a high evaluation: Optimus's hand is the world's five-fingered robot. One of the most dexterous. Its hands are not only tactile

Recently, the military circle has been overwhelmed by the news: US military fighter jets can now complete fully automatic air combat using AI. Yes, just recently, the US military’s AI fighter jet was made public for the first time and the mystery was unveiled. The full name of this fighter is the Variable Stability Simulator Test Aircraft (VISTA). It was personally flown by the Secretary of the US Air Force to simulate a one-on-one air battle. On May 2, U.S. Air Force Secretary Frank Kendall took off in an X-62AVISTA at Edwards Air Force Base. Note that during the one-hour flight, all flight actions were completed autonomously by AI! Kendall said - "For the past few decades, we have been thinking about the unlimited potential of autonomous air-to-air combat, but it has always seemed out of reach." However now,
