13.07.2015 Views

Software Engineering for Internet Applications - Student Community

Software Engineering for Internet Applications - Student Community

Software Engineering for Internet Applications - Student Community

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

from (select *from content_versionswhere content_id = 5657and editorial_status = 'approved'order by version_date desc)where rownum = 1;Another common style of programming in SQL that may seemsurprising is taking the following steps:1. open a cursor <strong>for</strong> the SQL statementselect *from content_versionswhere content_id = 5657and editorial_status = 'approved'order by version_date desc2. fetch one row from the cursor (this will be the one with the maxvalue in version_date)3. close the cursor6.13 Third Normal FormAn efficiency-minded programmer might look at the precedingqueries and observe that a content version is updated at most 10times per year while the public pages may be querying <strong>for</strong> anddelivering the latest version 10 times per second. Wouldn't it makemore sense to compute and tag the most current approved version atinsertion/update time?create table content_versions (version_id integer primary key,content_id not null references content_raw,version_date date not null,...editorial_status varchar(30)check (editorial_status in('submitted','rejected','approved','expired')),current_version_p char(1)check(current_version_p in ('t','f')),...);create table content (content_id integer primary key,refers_to references content_raw,-- who contributed this and whencreation_user not null references users,creation_date not null date,modified_date not null date,mime_type varchar(100) not null,one_line_summary varchar(200) not null,body clob,editorial_status varchar(30)check (editorial_status in('submitted','rejected','approved','expired')));-- create an Oracle Text index (the product used to-- be called Oracle Context, hence the CTX prefixes-- on many procedures)create index content_texton content(body)indextype is ctxsys.context;-- let's look at opinions on running shoes from-- users who registered in the last 30 days,-- sorting results in order of decreasing relevanceselectscore(1),content.content_id,content.one_line_summary,users.first_names,users.last_namefrom content, userswhere contains(body, 'running shoes', 1) > 0and users.registration_date > current_timestamp -interval '30' dayand content.creation_user = users.user_idorder by score(1) desc;In the preceding example, Oracle Text builds its own index on thebody column of the content table. When a Text index is defined ona table it becomes possible to use the contains operator in aWHERE clause. The Oracle RDBMS SQL query processor is smartenough to know how to use the Text index to answer this querywithout doing a sequential table scan. It is possible to have more114235

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!