原来面试的时候,是作为面试题背的..什么MySQL In 使用Exists方式,很慢...面试官问怎么办..回答用内连接改写..然后面试官露出满意
原来面试的时候,,是作为面试题背的..
什么MySQL In 使用Exists方式,很慢...
面试官问怎么办..回答用内连接改写..
然后面试官露出满意笑容..
一直以来都是这个剧本..
直到昨天我才发现..这个剧本原来是错的.
实验数据
create table song(
songid int
);
insert into song values(1),(2),(3);
create table song_category_relation(
Category varchar(10),
songid int
);
insert into song_category_relation values
('华语',1),
('华语',2),
('华语',3),
('热门',3);
song是歌曲表
song_category_relation是歌曲和分类的映射关系表.
一个歌曲可能有多个分类.
需求.
已知一个歌曲的ID,找到这个歌曲所属的所有分类,然后再找到所有分类下的所有歌曲.
使用In
select * from song where songid in (
select songid from song_category_relation where Category in
(select Category from song_category_relation where songid=3)
);
但是此时如果用内连接改写..
select * from song inner join (
select songid from song_category_relation where Category in
(select Category from song_category_relation where songid=3)
) a on (a.songid=song.songid);
可以看到,两种方式的结果并不相同..
从逻辑上看,In后面的子查询经过了去重.
原来是通过Exists实现的.MySQL 5.6之后,采用了Semi Join优化.
半连接(Semi Join) 参考:
本文永久更新链接地址:

mysqlviewshavelimitations : 1) 그들은 upportallsqloperations, datamanipulation throughviewswithjoinsorbqueries를 제한하지 않습니다

적절한 usermanagementInmysqliscrucialforenhancingsecurityandensuringfefficientDatabaseOperation.1) USECREATEUSERTOWDDUSERS,@'localHost'or@'%'.

mysqldoes notimposeahardlimitontriggers, butpracticalfactorsdeteirefectiveuse : 1) ServerConfigurationimpactStriggerManagement; 2) 복잡한 트리거 스케일 스케일 사이드로드; 3) argertableSlowtriggerTriggerPerformance; 4) High ConconcercencyCancaUspriggerContention; 5) m

예, It 'safetostoreBlobdatainmysql, butconsidertheStefactors : 1) StoragesPace : BlobScanconSumeSignificantspace, 잠재적으로 증가하는 CostsandSlownperformance

PHP 웹 인터페이스를 통해 MySQL 사용자를 추가하면 MySQLI 확장 기능을 사용할 수 있습니다. 단계는 다음과 같습니다. 1. MySQL 데이터베이스에 연결하고 MySQLI 확장자를 사용하십시오. 2. 사용자를 생성하고 CreateUser 문을 사용하고 Password () 함수를 사용하여 암호를 암호화하십시오. 3. SQL 주입 방지 및 MySQLI_REAL_ESCAPE_STRING () 함수를 사용하여 사용자 입력을 처리하십시오. 4. 새 사용자에게 권한을 할당하고 보조금 명세서를 사용하십시오.

mysql'sblobissuilableforstoringbinarydatawithinareldatabase, whilenosqloptionslikemongodb, redis, and cassandraofferflexible, scalablesolutionsforunstuctureddata.blobissimplerbutcanslowwownperformance를 사용하는 것들보업 betterscal randaysand

TOADDAUSERINMYSQL, 사용 : CreateUser'UserName '@'host'IdentifiedBy'Password '; 여기서'showTodoitseciRely : 1) ChoosetheHostCareLyTocon trolaccess.2) setResourcelimitswithOptionslikemax_queries_per_hour.3) Usestrong, iriquepasswords.4) enforcessl/tlsconnectionswith

toavoidcommonmistakeswithstringdatatypesinmysql, stroundStringTypenuances, chooseTherightType, andManageEncodingAndCollationSettingSefectively.1) usecharforfixed-lengthstrings, varcharvariable-length, andtext/blobforlargerdata.2) setcarcatter


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!