Rule based query

Hi all,
please forward information about Rule Based Query, actually i am nott getting what is rule based query, please help me out....
Thanks and Regards,
Santosh

rule based optimizer is a older technique and cannot be used efficiently to optimize a query, now -a- days only cost based optimization would be effective and these are categories under which a query can be tuned. usually explain plan on a query would fetch you the rule or cost based information....Thank you

Similar Messages

  • Dynamic Rule based implementation in PL/SQL

    Hi,
    We are trying to implement a dynamic rule based application in Oracle 9i. Its simple logic where we store expressions as case statments and actions seperated by commas as follows.
    Rule: 'Age > 18 and Age <65'
    True Action: 'Status = ''Valid'' , description = ''age in range'''
    False Action: 'Status =''Invalid'', Description=''Age not in range'''
    Where Age,Status, description are all part of one table.
    One way of implementing this is fire rule for each record in the table and then based on true or false call action as update.
    i.e
    select (case when 'Age > 18 and Age <65' then 1 else 0 end) age_rule from tableX
    (above query will in in a cursor xcur)
    Then we search for
    if age_rule = 1 then
    update tablex set Status = ''Valid'' , description = ''age in range'' where id=xcur.id;
    else
    update tablex set Status =''Invalid'', Description=''Age not in range'' where id=xcur.id;
    end if;
    This method will result in very slow performance due to high i/o. We want to implement this in collection based method.
    Any ideas on how to dynamically check rules and apply actions to collection without impact on performance. (we have nearly 3million rows and 80 rules to be applied)
    Thanks in advance

    Returning to your original question, first of all, there is a small flaw in the requirements, because if you apply all the rules to the same table/cols, than the table will have results of only last rule that was processed.
    Suppose rule#1:
    Rule: 'Age > 18 and Age <65'
    True Action: 'Status = ''Valid'' , description = ''age in range'''
    False Action: 'Status =''Invalid'', Description=''Age not in range'''
    and Rule#2:
    Rule: 'Name like ''A%'''
    True Action: 'Status = 'Invalid'' , description = ''name begins with A'''
    False Action: 'Status =''Invalid'', Description=''name not begins with A'''
    Then after applying of rule#1 and rule#2, results of the rule#1 will be lost, because second rule will modify the results of the first rule.
    Regarding to using collections instead of row by row processing, I think that a better approach would be to move that evaluating cursor inside an update statement, in my tests this considerably reduced processed block count and response time.
    Regarding to the expression filter, even so, that you are not going to move to 10g, you still can test this feature and see how it is implemented, to get some ideas of how to better implement your solution. There is a nice paper http://www-db.cs.wisc.edu/cidr2003/program/p27.pdf that describes expression filter implementation.
    Here is my example of two different methods for expression evaluation that I've benchmarked, first is similar to your original example and second is with expression evaluation moved inside an update clause.
    -- fist create two tables rules and data.
    drop table rules;
    drop table data;
    create table rules( id number not null primary key, rule varchar(255), true_action varchar(255), false_action varchar(255) );
    create table data( id integer not null primary key, name varchar(255), age number, status varchar(255), description varchar(255) );
    -- populate this tables with information.
    insert into rules
    select rownum id
    , 'Age > '||least(a,b)||' and Age < '||greatest(a,b) rule
    , 'Status = ''Valid'', description = ''Age in Range''' true_action
    , 'Status = ''Invalid'', description = ''Age not in Range''' false_action
    from (
    select mod(abs(dbms_random.random),60)+10 a, mod(abs(dbms_random.random),60)+10 b
    from all_objects
    where rownum <= 2
    insert into data
    select rownum, object_name, mod(abs(dbms_random.random),60)+10 age, null, null
    from all_objects
    commit;
    -- this is method #1, evaluate rule against every record in the data and do the action
    declare
    eval number;
    id number;
    data_cursor sys_refcursor;
    begin
    execute immediate 'alter session set cursor_sharing=force';
    for rules in ( select * from rules ) loop
    open data_cursor for 'select case when '||rules.rule||' then 1 else 0 end eval, id from data';
    loop
    fetch data_cursor into eval, id;
    exit when data_cursor%notfound;
    if eval = 1 then
    execute immediate 'update data set '||rules.true_action|| ' where id = :id' using id;
    else
    execute immediate 'update data set '||rules.false_action|| ' where id = :id' using id;
    end if;
    end loop;
    end loop;
    end;
    -- this is method #2, evaluate rule against every record in the data and do the action in update, not in select
    begin
    execute immediate 'alter session set cursor_sharing=force';
    for rules in ( select * from rules ) loop
    execute immediate 'update data set '||rules.true_action|| ' where id in (
    select id
    from (
    select case when '||rules.rule||' then 1 else 0 end eval, id
    from data
    where eval = 1 )';
    execute immediate 'update data set '||rules.false_action|| ' where id in (
    select id
    from (
    select case when '||rules.rule||' then 1 else 0 end eval, id
    from data
    where eval = 0 )';
    end loop;
    end;
    Here are SQL_TRACE results for method#1:
    call count cpu elapsed disk query current rows
    Parse 37 0.01 0.04 0 0 0 0
    Execute 78862 16.60 17.50 0 187512 230896 78810
    Fetch 78884 3.84 3.94 2 82887 1 78913
    total 157783 20.46 21.49 2 270399 230897 157723
    and this is results for method#2:
    call count cpu elapsed disk query current rows
    Parse 6 0.00 0.00 0 0 0 0
    Execute 6 1.93 12.77 0 3488 170204 78806
    Fetch 1 0.00 0.00 0 7 0 2
    total 13 1.93 12.77 0 3495 170204 78808
    You can compare this two methods using SQL_TRACE.

  • Document rule based classification

    from the example in oracle text developers guide i tried to build a rule based document classification, using the code given below:
    create or replace package classifier as
    procedure this;
    end;
    show errors
    create or replace package body classifier as
    procedure this
    is
    v_document     blob;
    v_item          number;
    v_doc           number;
    begin
    for doc in (select document_id, content from documents)
         loop
              v_document :=doc.content;
              v_item:=0;
              v_doc:=doc.document_id;
              for c in (select category_id, category_name from docs_cats_rule_based_class
                   where matches(query,v_document)>0)
              loop
                   v_item:=v_item +1;
                   insert into doc_cat_rule_based_class values (doc.document_id, category_id);
              end loop;
         end loop;
    end this;
    end;
    show errors
    exec classifier.this
    this gives the following errors:
    package classifier Compiled.
    line 5: SQLPLUS Command Skipped: show errors
    package body Compiled.
    line 32: SQLPLUS Command Skipped: show errors
    Error starting at line 33 in command:
    exec classifier.this
    Error report:
    ORA-04063: package body "STARDOC.CLASSIFIER" has errors
    ORA-06508: PL/SQL: could not find program unit being called: "STARDOC.CLASSIFIER"
    ORA-06512: at line 1
    i think i am missing some grant to package. please help!

    What version of Oracle are you using? Did you create the required tables and index in the earlier steps? What did you run it from? It appears that you did not run it from SQL*Plus. Please see the following demonstration that shows that it works fine on Oracle 10g when run from SQL*Plus with minimal privileges. I did not use any data.
    SCOTT@10gXE> CREATE USER stardoc IDENTIFIED BY stardoc
      2  /
    User created.
    SCOTT@10gXE> GRANT CONNECT, RESOURCE TO stardoc
      2  /
    Grant succeeded.
    SCOTT@10gXE> CONNECT stardoc/stardoc
    Connected.
    STARDOC@10gXE>
    STARDOC@10gXE> create table news_table
      2    (tk    number primary key not null,
      3       title varchar2(1000),
      4       text  clob)
      5  /
    Table created.
    STARDOC@10gXE> create table news_categories
      2    (queryid  number primary key not null,
      3       category varchar2(100),
      4       query      varchar2(2000))
      5  /
    Table created.
    STARDOC@10gXE> create table news_id_cat
      2    (tk         number,
      3       category_id number)
      4  /
    Table created.
    STARDOC@10gXE> create index news_cat_idx on news_categories (query)
      2  indextype is ctxsys.ctxrule
      3  /
    Index created.
    STARDOC@10gXE> create or replace package classifier
      2  as
      3    procedure this;
      4  end classifier;
      5  /
    Package created.
    STARDOC@10gXE> show errors
    No errors.
    STARDOC@10gXE> create or replace package body classifier
      2  as
      3    procedure this
      4    is
      5        v_document    clob;
      6        v_item        number;
      7        v_doc            number;
      8    begin
      9        for doc in (select tk, text from news_table)
    10        loop
    11          v_document := doc.text;
    12          v_item := 0;
    13          v_doc  := doc.tk;
    14          for c in
    15            (select queryid, category from news_categories
    16             where matches (query, v_document) > 0)
    17          loop
    18             v_item := v_item + 1;
    19             insert into news_id_cat values (doc.tk,c.queryid);
    20          end loop;
    21        end loop;
    22    end this;
    23  end classifier;
    24  /
    Package body created.
    STARDOC@10gXE> show errors
    No errors.
    STARDOC@10gXE> exec classifier.this
    PL/SQL procedure successfully completed.
    STARDOC@10gXE>

  • Query rule using query variables

    Hi All,
    I am working on a query rule in SharePoint 2013. I am trying to build a query text using query variables to provide profile based results to the users. The query text which I am using in the query builder is of the following format:
    {SearchBoxQuery} CombinedLanguage:{User.PreferredContentLanguage}
    but its not taking the user.preferredcontentlanguage value. Has any one worked on similar type of query rules using query variables? Please share your suggestions.
    Thanks !!

    Hi,
    As I understand, you cannot get the user.preferredcontentlanguage value.
    1. Make sure you have set the value of query variable {user.preferredcontentlanguage}, it will return -1 if not set.
    2. Make sure you search in the right result source.
    3. Please check the crawled property mapped to the managed property CombinedLanguage and make sure that there is at least one value indexed by the crawled property equal to the {user.preferredcontentlanguage}.
    The article below is about the query variables.
    https://technet.microsoft.com/en-us/library/jj683123.aspx
    The article below is about the different query variables return different result examples.
    http://techmikael.blogspot.in/2014/05/s15e03-query-variables-constant-trouble.html
    Best regards
    Sara Fan
    TechNet Community Support

  • Re: Oracle 8i (8.1.7.4) Rule based v/s Cost based

    Hi,
    I would like to know the advantages/disadvantages of using RULE based optimizer v/s COST based optimizer in Oracle 8i. We have a production RULE based database and are experiencing performance issues on some queries sporadically.
    TKPROF revealed:
    call       count       cpu    elapsed             disk                  query                current              rows
    Parse        0      0.00       0.00                0                      0                      0                      0
    Execute      3     94.67    2699.16            1020421            5692711            51404               0
    Fetch       13    140.93    4204.41             688482             4073366            0                      26896
    total       16       235.60    6903.57           1708903            9766077            51404               26896
    Please post your expert suggestions as soon as possible.
    Thanks and Regards,
    A

    I think the answer you are looking for is that Rule Based optimizer is predictive, but Cost Based optimizer results may vary depending on statistics of rows, indexes, etc. But at the same time, you can typically get better speed for OLTP relational databases with CBO, assuming you have correct statistics, and correct optimizer settings set.

  • Connect SharePoint to SQL Server Database Then Build Rules Based Returns System

    Hello Guys,
    I work for an ecommerce business. We sell a wide range of products to customers all around the world which are ordered from our websites and then dispatched to our customers from our warehouses.
    I have been tasked with developing a computerised return system from the company because at the moment everything is done using paper forms.
    We have all our customer, order and product data within SQL Server databases.
    What I would like to know is...
    1. Can we connect sharepoint online to a local sql server database
    2. Could we then build searches within sharepoint to display data contained within these databases e.g. customer information etc
    3. How is the data presented in sharepoint - is there a way to design how the data is displayed within sharepoint etc?
    4. Can we then build a rules based return system within sharepoint? The on screen workflow would need to vary according to data contained within the database e.g. the weight if the product being returned and also on fields input by the service agent such
    as the reason for the return, what solution the customer would like etc.
    5. is it possible to build these workflows in such a way that they can be saved part way through then gone back to later
    6. Can reports be build based on the returns that are being generated e.g. list of products most commonly returned
    Sorry for all the questions, I am a bit of sharepoint novice. I think it may possible be able to do what we need but I just wondered if the answer to any of the above questions is definately a no because if it is that could mean it is not suitable
    Thanks

    You could use a BCS connection
    http://community.office365.com/en-us/b/office_365_community_blog/archive/2012/10/11/business-data-connectivity-services-in-office-365-sharepoint-online.aspx, this will allow you to edit data in your non SharePoint SQL DB, on premises, from Office 365 SharePoint.
    Search will index the web applications you point it at, and the lists from the BCS will be part of those web apps, site collections, sites at some place and will get indexed. 
    You can create views on the data, that can sort of work like a search, but when you search on the site where the lists are the query will return results based on the BCS data.
    These views can be based on criteria such as the weight of the product being returned and other fields.
    The data is presented as a list.
    You can make it read only or read-write based on SharePoint permissions on the list.  The account used to create the connection can edit.
    BCS is possible in on-premises SharePoint too
    here is a good read on it,
    http://www.dotnetcurry.com/showarticle.aspx?ID=632
    Stacy Simpkins | MCSE SharePoint | www.sharepointpapa.com

  • Rule based on a block

    Hi I have a block that is based on many tables, 4 actually. I'm using forms 10g release 1 and the database is oracle 10g.
    The block is very slow because the query is cost based. When I'm launching the same query with the hint /*+ rule */ the query is pretty fast. 4 minutes vs 400 miliseconds. Is there a way to tell the block that I want it rule based?
    When I based the block on a view, I can specify the rule based hint, but I can't have the block based on a view, because I don't to update the block. The view is a bit complicated to be updateable. A view is updateable if the view have the primary key, and the join foreing key or something like that. Anyway I create the view and I include the primary key and I can't update it.
    Do anyone know how I can add hint in a block in forms?
    Thank you

    Hi,
    you could create a pre-query trigger that does the following
    set_block_property('block_name', OPTIMIZER_HINT, 'RULE');
    but as Francois suggests, i'd look at why the optimiser is producing such a poor plan
    Hope this helps
    Neil

  • RULE BASED OPTIMIZER TUNING

    Hi all,
    On one of the production server we are using RULE BASED OPTIMIZER(Its application requirement).
    I have to tune this database as users are complaining about the performance.
    Any tips how can I tune for a RULE BASED optimizer database.
    Does the tuning statergy will remain same as like seeing execution plan for missing index,instance paramets
    execpt you cant generate stats.
    Regards
    Umair

    Hi!
    There are one thing about RBO, YOU must check all long-running queryis for it's
    execution plans, try find better plans and after force RBO to using it.
    You can use different hints for changing eceution plans. But for tuning RBO's database you must soent a very big time, YOU must be a CBO ;)

  • Rule based availability check

    Hi,
    Please provide step by step guide instructions for rule based availability check configuration. Your help is highly appreciated.
    Thanks
    Chandana

    Hi Chandana,
    I have provided the below link which contains the full details of step by
    step configuration of rule based availability check
    http://help.sap.com/saphelp_scm70/helpdata/EN/fb/e6783739e6ff5de10000009b38f8cf/frameset.htm
    Please confirm your query is resolved
    Regards
    R. Senthil Mareeswaran.

  • Rule based Optimiser in 10g

    Can anyone tell me if there is still a rule based optimiser in 10g, i have heard that it has been removed? Is this correct?

    Here's what's in the Database Performance Tuning Guide 10g Release 1:
    Rule-based Optimization (RBO) Obsolescence
    RBO as a functionality is no longer supported. RBO still exists in Oracle 10g Release 1, but is an unsupported feature. No code changes have been made to RBO and no bug fixes are provided. Oracle supports only the query optimizer, and all applications running on Oracle Database 10g Release 1 (10.1) should use that optimizer. Please review the following Oracle Metalink desupport notice (189702.1) for RBO:
    http://metalink.oracle.com/metalink/plsql/ml2_documents.showDocument?p_
    database_id=NOT&p_id=189702.1
    You can also access desupport notice 189702.1 and related notices by searching for "desupport of RBO" at:
    http://metalink.oracle.com
    Notice 189702.1 provides details about the desupport of RBO and the migration of applications based on RBO to query optimization.
    Some consequences of the desupport of RBO are:
    CHOOSE and RULE are no longer supported as OPTIMIZER_MODE initialization parameter values and a warning is displayed in the alert log if the value is set to RULE or CHOOSE. The functionalities of those parameter values still exist but will be removed in a future release. See "OPTIMIZER_MODE Initialization Parameter" for information optimizer mode parameters.
    ALL_ROWS is the default value for the OPTIMIZER_MODE initialization parameter.
    The CHOOSE and RULE optimizer hints are no longer supported. The functionalities of those hints still exist but will be removed in a future release.
    Existing applications that previously relied on rule-based optimization (RBO) need to be moved to query optimization.
    HTH

  • Rule based & Cost based optimizer

    Hi,
    What is the difference Rule based & Cost based optimizer ?
    Thanks

    Without an optimizer, all SQL statements would simply do block-by-block, row-by-row table scans and table updates.
    The optimizer attempts to find a faster way of accessing rows by looking at alternatives, such as indexes.
    Joins add a level of complexity - the simplest join is "take an appropriate row in the first table, scan the second table for a match". However, deciding which is the first (or driving) table is also an optimization decision.
    As technology improves a lot of different techiques for accessing the rows or joining that tables have been devised, each with it's own optimium data-size:performance:cost curve.
    Rule-Based Optimizer:
    The optimization process follows specific defined rules, and will always follow those rules. The rules are easily documented and cover things like 'when are indexes used', 'which table is the first to be used in a join' and so on. A number of the rules are based on the form of the SQL statement, such as order of table names in the FROM clause.
    In the hands of an expert Oracle SQL tuner, the RBO is a wonderful tool - except that it does not support such advanced as query rewrite and bitmap indexes. In the hands of the typical developer, the RBO is a surefire recipie for slow SQL.
    Cost-Based Optimizer:
    The optimization process internally sets up multiple execution proposals and extrapolates the cost of each proposal using statistics and knowledge of the disk, CPU and memory usage of each of the propsals. It is not unusual for the optimizer to analyze hundred, or even thousands, of proposals - remember, something as simple as a different order of table names is a proposal. The proposal with the least cost is generally selected to be executed.
    The CBO requires accurate statistics to make reasonable decisions.
    Even with good statistics, the complexity of the SQL statement may cause the CBO to make a wrong decision, or ignore a specific proposal. To compensate for this, the developer may provide 'hints' or recommendations to the optimizer. (See the 10g SQL Reference manual for a list of hints.)
    The CBO has been constantly improving with every release since it's inception in Oracle 7.0.12, but early missteps have given it a bad reputation. Even in Oracle8i and 9i Release 1, there were countless 'opportunities for improvement' <tm> As of Oracle 10g, the CBO is quite decent - sufficiently so that the RBO has been officially deprecated.

  • Rule-Based Optimizer doesn4t use the index

    Does anybody know why the rule-based optimizer doesn4t use the index of all columns in the where clause?
    I have a select that use the hint RULE to force the optimizer to work in rule mode and also one index to all columns used in the where clause. Analyzing the execution plan (EXPLAIN PLAN) I observed the optimizer accesses all tables, but one, using the index. There4s one table (the first of the execution plan) that is accessed using a Full Table Scan (FTS).
    I've rebuilt the index for this table, but the execution plan doesn4t change.
    Any suggestions?
    Thanks in advance.
    Eliane.

    Hi. Oracle may not use an index if it finds that a full table scan is quicker/more efficient. Try the hint /*+ INDEX (table index) */ and compare the query performance with that of the one without this hint. (As you know, if you force Rule-based approach, the COST column in EXPLAIN PLAN output will not be populated. You may have to use trace/tkprof.)

  • Rule Based Optimization

    Hi,
    Rule Based Optimization is a deprecated feature in Oracle 10g.We are in the process of migrating from Oracle 9i to 10g.I have never heard of this Rule based Optimization earlier.I have googled for the same.But, got confused with the results.
    Can anybody shed some light on the below things...
    Is this Optimization done by Oracle or as a developer do we need to take care of the rules while writing SQL statements?
    There is another thing called Cost Based Optimization...
    Who will instruct the Oracle whether to use Rule Based Optimization or cost Based Optimization?
    Thanks & Regards,
    user569598

    Hope the following explanation would be helpful.
    Whenever a statement is fired, Oracle should goes through the following stages:
    Parse -> Execute -> Fetch (fetch only for select statement).
    During Parse, Oracle first evaluates, Syntatic checking (SELECT, FROM, WHERE, ORDER BY ,GROUP and etc) and then Semantic Checking (columns names, table name, user permission on the objects and etc). Once these two stages passes, then, it has to decided whether to do soft parse or hard parse. If similar cursor(statement) doesn't exits in the shared pool, Oracle goes for Hard parse where Optimizer comes in picture for generating query plan.
    Oracle has to decide either RBO or CBO. It also depends on the OPTIMIZER_MODE parameter value. If RULE hint is used, RBO will be used, if there are no statistics for those tables involved in the query, Oracle decides RBO, (condition applies). If statistics are available, or dynamic samplying is defined then Oracle use CBO to prepare the Optimal execution plan.
    RBO is simply relies on set of rules where CBO relies on statistical information.
    Jaffar

  • Rule based optimizer vs Cost based optimizer - 9i

    Is Rule based optimizer not used any more or can be used depending on the application etc.
    I think Rule based optimizer still has some advantages. Please give your input if you think otherwise.
    Thx

    I think Rule based optimizer still has some
    advantages. Please give your input if you think
    otherwise.You are absolutely correct. There are a few advantages to RBO.
    RBO is better for any application that meets the following criteria:
    - designed for Oracle version 7;
    - has not been updated since Oracle 7;
    - was hand tuned in Oracle 7;
    - will not be upgraded to Oracle Database 10g (where RBO is obsolete);
    - will not use Bitmap Indexes, Materialized Views, Query Rewrite, or vitrtually anything that was introduced in Oracle8 and beyond.
    CBO, while not perfect, will allow new features to be used. And it is improving with every release.

  • Delivery & Invoice for Rules based ATP check materials

    Hi All,
    We have an query regarding rules based ATP , delivery & Invoicing . When we create a SO ( say we have only one line item 10 , with quantity 100 created at Plant P1 , item category TAN ) , ATP confirmation happens   ,based on the stock & receipts ( say we have confirmation of 60 units at Plant P1  ) . Since we are using RBATP , the remaining 40 quantity is being confirmed at Plant P2.  Now the order will have multiple line items 10 the original line item but with different item category TAPA and also two more line items  for quantity of 60 & 40  for plants P1 & Plants P2 respectively with item category TAN. This is the standard functionality.
    My question is , Will there be any issues with respect to delivery & Invoicing  as there are multiple plants and different item categories.
    Thanks & Regards
    Surendra

    Hi,
    With respect  to delivery you will have differnt delivey document because your shipping point is going to be different.
    Regarding Billing you can combine the differnet delivey document if the delivery document created using the sales order contains the same payer,payment terms, billing date,material group and Incoterms.
    Apart from the above you will not face anyproblem by having 2 diiferent item category for the above said scenario..
    Regards,
    V.Devaselvam.

Maybe you are looking for