SQL之LIMIT子句踩坑记录

部分场景下,我们可能希望从一个大表 unparsed 中抽取前100行并对这些行应用UDF,一种容易想到的SQL语句如下:

sql 复制代码
@pyspark
insert into table parsed
select url, parse_func(content) as parsed_content from unparsed
limit 100;

但这个语句实际上会对 unparsed 中的所有行先应用UDF然后再抽取前100行,不符合我们的期望,为此可以作出如下修改

sql 复制代码
@pyspark
insert into table parsed
select url, parse_func(content) as parsed_content
from (
    select url, content from unparsed
    limit 100
);

注意,以下这种语句是无效的,速度并不会有任何改变:

sql 复制代码
@pyspark
insert into table parsed
(select url, parse_func(content) as parsed_content from unparsed limit 100);
相关推荐
dLYG DUMS3 分钟前
DBeaver连接本地MySQL、创建数据库表的基础操作
数据库·mysql
kumat1 小时前
分享-搭建个人系统 MySelfSys
sql·系统
苍煜1 小时前
MySQL分库分表和ES到底怎么选?
数据库·mysql·elasticsearch
茉莉玫瑰花茶1 小时前
Qt 信号与槽 [ 1 ]
开发语言·数据库·qt
czlczl200209251 小时前
松散索引扫描/跳跃索引扫描
数据库·mysql·性能优化
星马梦缘3 小时前
数据库作战记录 实验7、8
数据库·sql·oracle
安逸sgr3 小时前
Hermes Agent + Obsidian 打造第二大脑(六):分层记忆系统的设计逻辑——L0/L1/L2/L3 四层记忆详解
数据库·agent·知识库·hermes·hermesagent
苍煜4 小时前
一篇讲懂分库分表:概念、spirngboot实战
数据库·oracle
梦想画家4 小时前
PostgreSQL 物化视图实战:从数据固化到智能刷新的全链路指南
数据库·postgresql·物化视图
weoptions4 小时前
简单sql注入中如何通过简单语句判断注入类型&注入方法
数据库·sql