Đang chuẩn bị liên kết để tải về tài liệu:
Joe Celko s SQL for Smarties - Advanced SQL Programming P34

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

Joe Celko s SQL for Smarties - Advanced SQL Programming P34. In the SQL database community, Joe Celko is a well-known columnist and purveyor of valuable insights. In Joe Celko's SQL for Smarties: Advanced SQL Programming, he picks up where basic SQL training and experience leaves many database professionals and offers tips, techniques, and explanations that help readers extend their capabilities to top-tier SQL programming. Although Celko denies that the book is about database theory, he nevertheless alludes to theory often to buttress his practical points. This title is not for novices, as the author points out. Instead, its intended audience. | 302 CHAPTER 15 EXISTS PREDICATE ------------------------------------------------------------------------- SELECT P1.emp_name was born on a day without a famous New Yorker FROM Personnel AS P1 WHERE Pl.birthday NOT IN SELECT Cl.birthday FROM Celebrities AS C1 WHERE C1.birth_city New York and you would think that the exists version would be SELECT P1.emp_name was born on a day without a famous New Yorker FROM Personnel AS P1 WHERE NOT EXISTS SELECT FROM Celebrities AS C1 WHERE C1.birth_city New York AND C1.birthday P1.birthday Assume that Gloria Glamour is our only New Yorker and we still do not know her birthday. The subquery will be empty for every employee in the not exists predicate version because her null birthday will not test equal to the known employee birthdays. That means that the not exists predicate will return true and we will get every employee to match to Ms. Glamour. But now look at the IN predicate version which will have a single NULL in the subquery result. This predicate will be equivalent to Personnel.birthday null which is always unknown and we will get no employees back. Likewise you cannot in general transform the quantified comparison predicates into exists predicates because of the possibility of NULL values. Remember that x ALL subquery is shorthand for x NOT IN subquery and x ANY subquery is shorthand for x IN subquery and it will not surprise you. In general the exists predicates will run faster than the in predicates. The problem is in deciding whether to build the query or the subquery first the optimal approach depends on the size and distribution of values in each and that cannot usually be known until runtime. 15.2 EXISTS and INNER JOINs The not exists predicate is almost always used with a correlated subquery. Very often the subquery can be flattened into a JOIN which 15.3 NOT EXISTS and OUTER JOINs 303 will frequently run faster than the original query. Our sample query can be converted into SELECT P1.emp_name has the same .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.