FAQ
Hi Friends,
I am having a very fundamental doubt,
what is the order of retrival of the clauses when all are inclueded in the select stament like.

Where
Group by
having
order by.

eg : select deptno,max(sal) from emp where job like 'SAL%' group by deptno having max(sal)>1000 order by deptno

Regards,
Srinivas

Search Discussions

  • Mark Richard at Sep 20, 2004 at 12:39 am
    Hi,

    The where clause must be processed first - since it removes atomic records
    of data. Next the group by has to be applied to determine the values of
    max(sal). This allows the having clause to be applied (which I tend to
    think of as "where clauses applied after group by"). Finally the order by
    can be applied to ensure the result set appears in the desired order.

    The trick of course is that Oracle is smart... In the process of applying
    the group by it has effectively accomplished the order by clause so it most
    likely won't execute another sort procedure. There are many scenario's
    where Oracle can accomplish multiple tasks at once and simplify the
    processing. But in terms of logical application - the order I mention
    above is correct.

    Regards,

    Mark.

    "Srinivas T"

    mins.com> cc:
    Sent by: Subject: HI
    oracle-l-bounce_at_fr
    eelists.org

    20/09/2004 15:28
    Please respond to
    SrinivasT

    Hi Friends,
    I am having a very fundamental doubt,
    what is the order of retrival of the clauses when all are inclueded in the
    select stament like.

    Where
    Group by
    having
    order by.

    eg : select deptno,max(sal) from emp where job like 'SAL%' group by deptno
    having max(sal)>1000 order by deptno

    Regards,
    Srinivas

    --
    http://www.freelists.org/webpage/oracle-l

    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<---->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    Privileged/Confidential information may be contained in this message.
    If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone.
    In such a case, you should destroy this message and kindly notify the sender by reply e-mail or by telephone on (03) 9612-6999 or (61) 3 9612-6999.
    Please advise immediately if you or your employer does not consent to Internet e-mail for messages of this kind.
    Opinions, conclusions and other information in this message that do not relate to the official business of Transurban Infrastructure Developments Limited and CityLink Melbourne Limited shall be understood as neither given nor endorsed by them.
    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<---->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    --
    http://www.freelists.org/webpage/oracle-l
  • Jared Still at Sep 20, 2004 at 9:39 am

    On Mon, 20 Sep 2004 15:41:34 +1000, Mark Richard wrote:

    The where clause must be processed first - since it removes atomic records
    of data. Next the group by has to be applied to determine the values of
    max(sal). This allows the having clause to be applied (which I tend to
    think of as "where clauses applied after group by"). Finally the order by
    can be applied to ensure the result set appears in the desired order.
    After recent discussions on this list regarding nested sub-queries, don't
    assume that Oracle will always process the WHERE clause first.

    (Check the archives )

    The simple query in the previous post won't be a problem, but it is
    nonetheless a dangerous assumption.

    Jonathan Gennick where are you? - care to comment?

    Jared
  • Jonathan Gennick at Sep 20, 2004 at 10:33 am
    Jonathan Gennick where are you? - care to comment?
    LOL! Well, I certainly think I've delved more deeply into
    subquery execution than I ever expected to :-)

    Looking back at the original post, I find this question:
    I am having a very fundamental doubt, what is the order of
    retrival of the clauses when all are inclueded in the
    select stament
    The SQL standard seems to define an ordering, but your
    database's optimizer might surprise you. Srinivas, if you
    haven't already, you might want to read the following
    articles:

    http://five.pairlist.net/pipermail/oracle-article/2004/000012.html

    http://asktom.oracle.com/pls/ask/f?p=4950:8:3825101693476404515::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:11504677087008

    http://www.dbdebunk.com/page/page/1351381.htm

    I don't want to become embroiled again in any argument about
    what is right or wrong. At this point, the important thing
    is probably to understand what the standard has to say, to
    understand that there is (or seems to be) disagreement over
    the whole issue, and to understand that a given vender may
    deviate from the standard for purposes of optimization.
    You'll probably never have problems unless your tables are
    poorly designed. The type-mismatch problem that began our
    whole discussion was the result of what was probably a poor
    design decision. I'll hedge just a bit, because I wasn't
    around when that decision was taken.

    I will also say this. I still find it helpful to work
    through writing a query in a stepwise fashion, beginning
    with the FROM clause. I don't know how others do it, but I
    like to begin, conceptually at least, with my tables and
    then work through the remaining clauses to refine the
    results to those rows that I ultimately want.

    Hope this helps.

    Best regards,

    Jonathan Gennick --- Brighten the corner where you are
    http://Gennick.com * 906.387.1698 * mailto:jonathan@gennick.com

    Join the Oracle-article list and receive one
    article on Oracle technologies per month by
    email. To join, visit http://five.pairlist.net/mailman/listinfo/oracle-article,
    or send email to Oracle-article-request_at_gennick.com and
    include the word "subscribe" in either the subject or body.

    Monday, September 20, 2004, 10:43:52 AM, Jared Still (jkstill_at_gmail.com) wrote:
    JS> On Mon, 20 Sep 2004 15:41:34 +1000, Mark Richard
    JS> wrote:
    The where clause must be processed first - since it removes atomic records
    of data. Next the group by has to be applied to determine the values of
    max(sal). This allows the having clause to be applied (which I tend to
    think of as "where clauses applied after group by"). Finally the order by
    can be applied to ensure the result set appears in the desired order.
    JS> After recent discussions on this list regarding nested sub-queries, don't
    JS> assume that Oracle will always process the WHERE clause first.

    JS> (Check the archives )

    JS> The simple query in the previous post won't be a problem, but it is
    JS> nonetheless a dangerous assumption.

    JS> Jonathan Gennick where are you? - care to comment?

    JS> Jared
    JS> --
    JS> http://www.freelists.org/webpage/oracle-l
  • Lex de Haan at Sep 20, 2004 at 10:59 am
    just to add my two cents, without the intention to open that discussion
    again;-)
    if you have a SQL statement containing WHERE, GROUP BY, and HAVING clauses,
    it would theoretically still be possible to do things in any order, I guess,
    but I am 99% sure that any optimizer would first evaluate the WHERE clause
    before the GROUP BY. and obviously, the HAVING must be processed after the
    GROUP BY.

    By the way, I think we should get rid of the GROUP BY alltogether -- SQL has
    much more powerful and elegant constructs to achieve the same results. think
    about correlated subqueries in the SELECT clause. But that might open up the
    discussion again about whether subquery merging is acceptable under all
    circumstances ... and I didn't want to go there;-)

    additions/corrections welcome,

    Kind regards,
    Lex.

    visit http://www.naturaljoin.nl

    skype me

    -----Original Message-----
    From: oracle-l-bounce_at_freelists.org
    On Behalf Of Jonathan Gennick
    Sent: Monday, September 20, 2004 16:37
    To: Jared Still
    Cc: mrichard_at_transurban.com.au; srinivast_at_kpitcummins.com;
    oracle-l_at_freelists.org
    Subject: Re[2]: HI
    Jonathan Gennick where are you? - care to comment?
    LOL! Well, I certainly think I've delved more deeply into
    subquery execution than I ever expected to :-)

    Looking back at the original post, I find this question:
    I am having a very fundamental doubt, what is the order of
    retrival of the clauses when all are inclueded in the
    select stament
    The SQL standard seems to define an ordering, but your
    database's optimizer might surprise you. Srinivas, if you
    haven't already, you might want to read the following
    articles:

    http://five.pairlist.net/pipermail/oracle-article/2004/000012.html

    http://asktom.oracle.com/pls/ask/f?p=4950:8:3825101693476404515::NO::F4950_P
    8_DISPLAYID,F4950_P8_CRITERIA:11504677087008

    http://www.dbdebunk.com/page/page/1351381.htm

    I don't want to become embroiled again in any argument about
    what is right or wrong. At this point, the important thing
    is probably to understand what the standard has to say, to
    understand that there is (or seems to be) disagreement over
    the whole issue, and to understand that a given vender may
    deviate from the standard for purposes of optimization.
    You'll probably never have problems unless your tables are
    poorly designed. The type-mismatch problem that began our
    whole discussion was the result of what was probably a poor
    design decision. I'll hedge just a bit, because I wasn't
    around when that decision was taken.

    I will also say this. I still find it helpful to work
    through writing a query in a stepwise fashion, beginning
    with the FROM clause. I don't know how others do it, but I
    like to begin, conceptually at least, with my tables and
    then work through the remaining clauses to refine the
    results to those rows that I ultimately want.

    Hope this helps.

    Best regards,

    Jonathan Gennick --- Brighten the corner where you are
    http://Gennick.com * 906.387.1698 * mailto:jonathan@gennick.com

    Join the Oracle-article list and receive one
    article on Oracle technologies per month by
    email. To join, visit
    http://five.pairlist.net/mailman/listinfo/oracle-article,
    or send email to Oracle-article-request_at_gennick.com and
    include the word "subscribe" in either the subject or body.

    Monday, September 20, 2004, 10:43:52 AM, Jared Still (jkstill_at_gmail.com)
    wrote:
    JS> On Mon, 20 Sep 2004 15:41:34 +1000, Mark Richard
    JS> wrote:
    The where clause must be processed first - since it removes atomic
    records
    of data. Next the group by has to be applied to determine the values of
    max(sal). This allows the having clause to be applied (which I tend to
    think of as "where clauses applied after group by"). Finally the order
    by
    can be applied to ensure the result set appears in the desired order.
    JS> After recent discussions on this list regarding nested sub-queries,
    don't
    JS> assume that Oracle will always process the WHERE clause first.

    JS> (Check the archives )

    JS> The simple query in the previous post won't be a problem, but it is
    JS> nonetheless a dangerous assumption.

    JS> Jonathan Gennick where are you? - care to comment?

    JS> Jared
    JS> --
    JS> http://www.freelists.org/webpage/oracle-l
  • Jonathan Gennick at Sep 20, 2004 at 12:17 pm
    Monday, September 20, 2004, 12:03:30 PM, Lex de Haan (lex.de.haan_at_naturaljoin.nl) wrote:

    LdH> By the way, I think we should get rid of the GROUP BY alltogether -- SQL has
    LdH> much more powerful and elegant constructs to achieve the same results. think
    LdH> about correlated subqueries in the SELECT clause.

    That's a fascinating thought, actually. I'll have to sit
    down sometime and line up all the uses I can think of for
    GROUP BY, and see whether I can solve those problems without
    GROUP BY. It'd be interesting to just run some tests of both
    approaches, to compare their relative efficiency, even if
    only in one implementation (e.g. Oracle).

    Best regards,

    Jonathan Gennick --- Brighten the corner where you are
    http://Gennick.com * 906.387.1698 * mailto:jonathan@gennick.com

    Join the Oracle-article list and receive one
    article on Oracle technologies per month by
    email. To join, visit http://five.pairlist.net/mailman/listinfo/oracle-article,
    or send email to Oracle-article-request_at_gennick.com and
    include the word "subscribe" in either the subject or body.
  • Lex de Haan at Sep 20, 2004 at 12:49 pm
    actually, although the optimizer is one of my hobbies,
    and I happen to know a little bit about the Oracle optimizer,
    in this case I am mainly interested in language elegance
    and not in performance, for a change;-)
    but anyway, I am indeed looking for GROUP BY statements
    (completely specified, including data structures and constraints)
    to check whether they can be rewritten without a GROUP BY.

    not only correlated subqueries in the SELECT clause come to mind,
    but also the analytical functions applied on row windows
    (both features being fully ANSI/ISO standard, by the way)

    could be a joint project with you, Jonathan...

    Kind regards,
    Lex.

    visit http://www.naturaljoin.nl <http://www.naturaljoin.nl>

    skype me

    -----Original Message-----
    From: oracle-l-bounce_at_freelists.org
    On Behalf Of Jonathan Gennick
    Sent: Monday, September 20, 2004 18:20
    To: Lex de Haan
    Cc: oracle-l_at_freelists.org
    Subject: Re[4]: HI

    Monday, September 20, 2004, 12:03:30 PM, Lex de Haan
    (lex.de.haan_at_naturaljoin.nl) wrote:
    LdH> By the way, I think we should get rid of the GROUP BY alltogether --
    SQL has
    LdH> much more powerful and elegant constructs to achieve the same results.
    think
    LdH> about correlated subqueries in the SELECT clause.

    That's a fascinating thought, actually. I'll have to sit
    down sometime and line up all the uses I can think of for
    GROUP BY, and see whether I can solve those problems without
    GROUP BY. It'd be interesting to just run some tests of both
    approaches, to compare their relative efficiency, even if
    only in one implementation (e.g. Oracle).

    Best regards,

    Jonathan Gennick --- Brighten the corner where you are
    http://Gennick.com * 906.387.1698 * mailto:jonathan@gennick.com

    Join the Oracle-article list and receive one
    article on Oracle technologies per month by
    email. To join, visit
    http://five.pairlist.net/mailman/listinfo/oracle-article,
    or send email to Oracle-article-request_at_gennick.com and
    include the word "subscribe" in either the subject or body.

    --
    http://www.freelists.org/webpage/oracle-l

    --
    http://www.freelists.org/webpage/oracle-l
  • SJHussain_at_alfransi.com.sa at Sep 20, 2004 at 1:15 am
    It will do a filter and sort for group by caluse to get the desired group
    by result and then orader by will take place.

    Best Regards,

    Syed Jaffar Hussain

    "Srinivas T"
    To
    Sent by:
    oracle-l-bounce_at_f cc
    reelists.org
    Subject
    HI
    09/20/2004 08:28
    AM

    Please respond to
    SrinivasT_at_KPITCum
    mins.com

    Hi Friends,
    I am having a very fundamental doubt,
    what is the order of retrival of the clauses when all are inclueded in the
    select stament like.

    Where
    Group by
    having
    order by.

    eg : select deptno,max(sal) from emp where job like 'SAL%' group by deptno
    having max(sal)>1000 order by deptno

    Regards,
    Srinivas

    --
    http://www.freelists.org/webpage/oracle-l

    Visit us on www.alfransi.com.sa
    ====== Banque Saudi Fransi - Privacy Notice ======
    This message is intended only for the person or entity to which it is
    addressed and may contain confidential and/or privileged material. Any
    use of this information by persons or entities other than the intended
    recipient is prohibited. If you have received this in error, please
    contact the sender and delete the material from your computer. Any
    opinions and other information contained in this message that do not
    relate to the official business of Banque Saudi Fransi shall be
    understood as neither given or endorsed by it. Although precautions
    have been taken to ensure no viruses are present in this email, BSF
    cannot accept responsibility for any loss or damage arising from the
    use of this email or attachments.
    ====== Banque Saudi Fransi - Privacy Notice ======

    --
    http://www.freelists.org/webpage/oracle-l
  • Stephane Faroult at Sep 20, 2004 at 6:59 am
    �Perhaps worth telling the original poster that Mark assumes, of course,
    thatyou request a sort by the columns you have grouped by, in which case the
    sort has already been done for grouping. If you sort by something else (for
    instance if the purpose of your GROUP BY is to compute a COUNT(*) and you
    want to order by decreasing COUNT(*), a common occurrence) there will be a
    (hopefully small and fast) sort.

    Regards,

    Stephane Faroult

    RoughSea Ltd
    http://www.roughsea.com

    On Mon, 20 Sep 2004 15:41, Mark Richard sent:

    The trick of course is that Oracle is smart... In the process of applying
    the group by it has effectively accomplished the order by clause so it most
    likely won't execute another sort procedure.

    "Srinivas T"

    mins.com> cc:
    Sent by: Subject: HI
    oracle-l-bounce_at_fr[3]
    eelists.org

    20/09/2004 15:28
    Please respond to
    SrinivasT

    Hi Friends,
    I am having a very fundamental doubt,
    what is the order of retrival of the clauses when all are inclueded in the
    select stament like.

    Where
    Group by
    having
    order by.

    eg : select deptno,max(sal) from emp where job like 'SAL%' group by deptno
    having max(sal)>1000 order by deptno

    Regards,
    Srinivas

    Links ---
    1 javascript:parent.opencompose('SrinivasT_at_KPITCum','','','')
    2 javascript:parent.opencompose('oracle-l_at_freelists.org','','','')
    3 javascript:parent.opencompose('oracle-l-bounce_at_fr','','','')
  • Wolfgang Breitling at Sep 20, 2004 at 12:59 pm
    I was trying to bite my tongue, but now it bleeds so I have to let go:

    In my opinion this is an irrelevant, if not invalid, question in a
    relational database. Relational databases are built on the theory of sets
    of relations and the valid operations ( projection(select),
    restriction(where) and join) upon them and as such do not have a concept of
    ordering. All operations can be reordered any which way following the
    operational rules.
    Questions like this, and trying to find THE answer, is what gets you into
    trouble. Just think of what the result of the query should look like, not
    how to achieve it. You can use any mental model to help you visualize - how
    to achieve - the result, as long as you remember that it is only a mental
    model and the actual path to achieve the result is up to the database engine.

    It's akin to aksing "What is the colour of the number 42?" (Mladen will
    probably say it's mauve).
    At 11:28 PM 9/19/2004, Srinivas T wrote:
    Hi Friends,
    I am having a very fundamental doubt,
    what is the order of retrival of the clauses when all are inclueded in the
    select stament like.

    Where
    Group by
    having
    order by.

    eg : select deptno,max(sal) from emp where job like 'SAL%' group by deptno
    having max(sal)>1000 order by deptno

    Regards,
    Srinivas


    --
    http://www.freelists.org/webpage/oracle-l
    Regards

    Wolfgang Breitling
    Centrex Consulting Corporation
    www.centrexcc.com
  • Singer, Phillip (P.W.) at Sep 20, 2004 at 1:34 pm

    -----Original Message-----
    From: oracle-l-bounce_at_freelists.org
    On Behalf Of Lex de Haan
    Sent: Monday, September 20, 2004 1:54 PM
    To: jonathan_at_gennick.com
    Cc: oracle-l_at_freelists.org
    Subject: RE: Re[4]: HI
    =20
    =20
    actually, although the optimizer is one of my hobbies,
    and I happen to know a little bit about the Oracle optimizer,
    in this case I am mainly interested in language elegance
    and not in performance, for a change;-)
    but anyway, I am indeed looking for GROUP BY statements
    (completely specified, including data structures and constraints)
    to check whether they can be rewritten without a GROUP BY.
    =20
    not only correlated subqueries in the SELECT clause come to mind,
    but also the analytical functions applied on row windows
    (both features being fully ANSI/ISO standard, by the way)
    =20
    O.K., I'll bite.

    I have always been under the opinion that

    SELECT col1, col2, col3, aggregate function() from foo
    group by col1, col2, col3

    was equivalent to (gave the same results as)

    SELECT distinct col1, col2, col3, same_thing_but_the_analytic =
    function_version()=20
    over (partition by col1, col2, col3)

    However, I have never used the latter syntax (except if I really needed
    the analytic function) because (1) nobody else around would understand =
    it, and
    (2) I was never that comfortable with it myself. So, I really don't =
    know how far
    off the truth I am.

    But I do know that if Lex and Johnathan were to expand this into a
    full length article I would finally feel really comfortable using them.
    =20
  • Wolfgang Breitling at Sep 20, 2004 at 1:41 pm
    I thought Oracle (and db2 and mssql) are relational dbs (with some object
    features veneered on). The crux as I see it is that the SQL language is not
    built on as rigorous a foundation as the relational algebra and as such let
    quite a bit of ambiguity creep in.

    Rethinking my statement above, you may be right that they all are not
    strictly relational DBs in that relational algebra does not have a concept
    of duplicates. Every tuple is uniquely identifiable.

    Just out of curiosity I dug out the course material of a course on Database
    Design by "The Relational Institute". The material has "copyright 1987 Codd
    & Date consulting group" on every page. In the chapter on Query
    Optimization under the heading "convert into canonical form" it lists
    several transformation rules:

    (A join B) where A-restriction and B-restriction ==> (A where
    A-restriction) join (B where B-restriction)

    any restriction predicate ==> equivalent predicate in conjunctive NF
    e.g. P or (Q and R) ==> (P or Q) and (P or R)

    (A where restriction 1) where restriction 2 ==> (A where restriction-1
    AND restriction-2)
    I love this particular one the most. Isn't that exactly the case where
    he was arguing in response to Jonathan's subquery madness article that the
    subquery must be evaluated before the outer restriction is applied???

    (A [projection-1]) [projection-2] ==> (A [projection-2])

    (A [projection]) where restriction ==> (A restriction) [projection]

    A.F1 > B.F2 and B.F2 = 3 ==> A.F1 > 3 (possibly allows the elimination
    of a join!!)

    others
    At 12:15 PM 9/20/2004, you wrote:
    You probably are correct Wolfgang, but I thought Oracle is NOT a
    relational db, but an
    SQL db, and if I understand Date correctly, then this qst has relevance.

    --
    Rob Zijlstra
    Regards

    Wolfgang Breitling
    Centrex Consulting Corporation
    http://www.centrexcc.com
  • Lex de Haan at Sep 20, 2004 at 1:59 pm
    the crux in the subquery madness debate was that SQL is missing
    functionality.
    what we have in mathematics is the concept of composition. For example,

    f(g(x)) means apply function g on x *first* and then apply function f on the
    result.
    f(g(x)) is not the same as g(f(x)) in general.

    this is elegant maths syntax to express precisely what you want to happen;
    in the subquery madness example, such syntax could make sure that you
    *first*
    filter column values *before* you try to apply a TO_NUMBER conversion.
    however, SQL doesn't make this clear distinction

    aaarrrggh, there you go -- it was *not* my intention to open that debate
    again...

    the operators from the relational algebra (like the restriction example,
    given below)
    indeed offer full freedom in their processing order.

    Kind regards,
    Lex.

    visit http://www.naturaljoin.nl <http://www.naturaljoin.nl>

    skype me

    -----Original Message-----
    From: oracle-l-bounce_at_freelists.org
    On Behalf Of Wolfgang Breitling
    Sent: Monday, September 20, 2004 19:45
    To: oracle-l_at_freelists.org
    Subject: Re: HI

    I thought Oracle (and db2 and mssql) are relational dbs (with some object
    features veneered on). The crux as I see it is that the SQL language is not
    built on as rigorous a foundation as the relational algebra and as such let
    quite a bit of ambiguity creep in.

    Rethinking my statement above, you may be right that they all are not
    strictly relational DBs in that relational algebra does not have a concept
    of duplicates. Every tuple is uniquely identifiable.

    Just out of curiosity I dug out the course material of a course on Database
    Design by "The Relational Institute". The material has "copyright 1987 Codd
    & Date consulting group" on every page. In the chapter on Query
    Optimization under the heading "convert into canonical form" it lists
    several transformation rules:

    (A join B) where A-restriction and B-restriction ==> (A where
    A-restriction) join (B where B-restriction)

    any restriction predicate ==> equivalent predicate in conjunctive NF
    e.g. P or (Q and R) ==> (P or Q) and (P or R)

    (A where restriction 1) where restriction 2 ==> (A where restriction-1
    AND restriction-2)
    I love this particular one the most. Isn't that exactly the case where
    he was arguing in response to Jonathan's subquery madness article that the
    subquery must be evaluated before the outer restriction is applied???

    (A [projection-1]) [projection-2] ==> (A [projection-2])

    (A [projection]) where restriction ==> (A restriction) [projection]

    A.F1 > B.F2 and B.F2 = 3 ==> A.F1 > 3 (possibly allows the elimination
    of a join!!)

    others
    At 12:15 PM 9/20/2004, you wrote:
    You probably are correct Wolfgang, but I thought Oracle is NOT a
    relational db, but an
    SQL db, and if I understand Date correctly, then this qst has relevance.

    --
    Rob Zijlstra
    Regards

    Wolfgang Breitling
    Centrex Consulting Corporation
    http://www.centrexcc.com
  • DBA Chirag at Sep 23, 2004 at 11:48 pm
    Herewith send ing the first mail..

    I think we have got many gurus here too..

    Chirag Majmundar
    +919886169102

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouporacle-l @
categoriesoracle
postedSep 20, '04 at 12:30a
activeSep 23, '04 at 11:48p
posts14
users10
websiteoracle.com

People

Translate

site design / logo © 2022 Grokbase