Return bool from query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • frizzle

    #1

    Return bool from query

    Hi there,

    I have a mySQL system with a news publishing part in it:
    Admins can create new items with text in it, and they have an option to
    create 'fulltexts', so you'd get "read more ..." on the front page,
    click it and read the fulltext.

    Is there a possibility for mySQL (query) to check if 'fulltext' is
    empty or not, and only return true or false, so i don't have to put the
    whole fulltext into the mysql_fetch_arr ay() to decide wether or not to
    show 'read_more', or should i create an extra boolean field in the DB
    saying fulltext y/n ?

    Greetings Frizzle.

  • Jerry Stuckle

    #2
    Re: Return bool from query

    frizzle wrote:[color=blue]
    > Hi there,
    >
    > I have a mySQL system with a news publishing part in it:
    > Admins can create new items with text in it, and they have an option to
    > create 'fulltexts', so you'd get "read more ..." on the front page,
    > click it and read the fulltext.
    >
    > Is there a possibility for mySQL (query) to check if 'fulltext' is
    > empty or not, and only return true or false, so i don't have to put the
    > whole fulltext into the mysql_fetch_arr ay() to decide wether or not to
    > show 'read_more', or should i create an extra boolean field in the DB
    > saying fulltext y/n ?
    >
    > Greetings Frizzle.
    >[/color]

    Put it in a separate table with just the article's id and the text. If
    the id exists in the second table, there is more text.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • frizzle

      #3
      Re: Return bool from query


      Jerry Stuckle wrote:[color=blue]
      > frizzle wrote:[color=green]
      > > Hi there,
      > >
      > > I have a mySQL system with a news publishing part in it:
      > > Admins can create new items with text in it, and they have an option to
      > > create 'fulltexts', so you'd get "read more ..." on the front page,
      > > click it and read the fulltext.
      > >
      > > Is there a possibility for mySQL (query) to check if 'fulltext' is
      > > empty or not, and only return true or false, so i don't have to put the
      > > whole fulltext into the mysql_fetch_arr ay() to decide wether or not to
      > > show 'read_more', or should i create an extra boolean field in the DB
      > > saying fulltext y/n ?
      > >
      > > Greetings Frizzle.
      > >[/color]
      >
      > Put it in a separate table with just the article's id and the text. If
      > the id exists in the second table, there is more text.
      >
      > --
      > =============== ===
      > Remove the "x" from my email address
      > Jerry Stuckle
      > JDS Computer Training Corp.
      > jstucklex@attgl obal.net
      > =============== ===[/color]

      This would have me quering against an extra table. Would'nt it be
      quicker to add an extra boolean field then?

      Frizzle.

      Comment

      • Jerry Stuckle

        #4
        Re: Return bool from query

        frizzle wrote:[color=blue]
        > Jerry Stuckle wrote:
        >[color=green]
        >>frizzle wrote:
        >>[color=darkred]
        >>>Hi there,
        >>>
        >>>I have a mySQL system with a news publishing part in it:
        >>>Admins can create new items with text in it, and they have an option to
        >>>create 'fulltexts', so you'd get "read more ..." on the front page,
        >>>click it and read the fulltext.
        >>>
        >>>Is there a possibility for mySQL (query) to check if 'fulltext' is
        >>>empty or not, and only return true or false, so i don't have to put the
        >>>whole fulltext into the mysql_fetch_arr ay() to decide wether or not to
        >>>show 'read_more', or should i create an extra boolean field in the DB
        >>>saying fulltext y/n ?
        >>>
        >>>Greetings Frizzle.
        >>>[/color]
        >>
        >>Put it in a separate table with just the article's id and the text. If
        >>the id exists in the second table, there is more text.
        >>
        >>--
        >>============= =====
        >>Remove the "x" from my email address
        >>Jerry Stuckle
        >>JDS Computer Training Corp.
        >>jstucklex@att global.net
        >>============= =====[/color]
        >
        >
        > This would have me quering against an extra table. Would'nt it be
        > quicker to add an extra boolean field then?
        >
        > Frizzle.
        >[/color]

        Why? Joins are quick. Probably a lot faster than unnecessarily
        processing empty text fields in the first table.

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • frizzle

          #5
          Re: Return bool from query

          Jerry Stuckle wrote:[color=blue]
          > frizzle wrote:[color=green]
          > > Jerry Stuckle wrote:
          > >[color=darkred]
          > >>frizzle wrote:
          > >>
          > >>>Hi there,
          > >>>
          > >>>I have a mySQL system with a news publishing part in it:
          > >>>Admins can create new items with text in it, and they have an option to
          > >>>create 'fulltexts', so you'd get "read more ..." on the front page,
          > >>>click it and read the fulltext.
          > >>>
          > >>>Is there a possibility for mySQL (query) to check if 'fulltext' is
          > >>>empty or not, and only return true or false, so i don't have to put the
          > >>>whole fulltext into the mysql_fetch_arr ay() to decide wether or not to
          > >>>show 'read_more', or should i create an extra boolean field in the DB
          > >>>saying fulltext y/n ?
          > >>>
          > >>>Greetings Frizzle.
          > >>>
          > >>
          > >>Put it in a separate table with just the article's id and the text. If
          > >>the id exists in the second table, there is more text.
          > >>
          > >>--
          > >>============= =====
          > >>Remove the "x" from my email address
          > >>Jerry Stuckle
          > >>JDS Computer Training Corp.
          > >>jstucklex@att global.net
          > >>============= =====[/color]
          > >
          > >
          > > This would have me quering against an extra table. Would'nt it be
          > > quicker to add an extra boolean field then?
          > >
          > > Frizzle.
          > >[/color]
          >
          > Why? Joins are quick. Probably a lot faster than unnecessarily
          > processing empty text fields in the first table.
          >
          > --
          > =============== ===
          > Remove the "x" from my email address
          > Jerry Stuckle
          > JDS Computer Training Corp.
          > jstucklex@attgl obal.net
          > =============== ===[/color]

          I understand what you're saying. I think i'm underestimating the speed
          of Joins (mySQL)
          Not to be a nag, but would it still be faster to add an extra field to
          the original table, 'fulltext_avail able' tinyint(1), which tells me to
          look for it or not?

          And, am i wrong believing that if i use 'SELECT fieldname1, name2 etc.'
          in the query, it leaves the unmentioned fields unbothered, thus not
          being influenced by their size/contents ?

          Frizzle.

          Comment

          • Jerry Stuckle

            #6
            Re: Return bool from query

            frizzle wrote:[color=blue]
            > Jerry Stuckle wrote:
            >[color=green]
            >>frizzle wrote:
            >>[color=darkred]
            >>>Jerry Stuckle wrote:
            >>>
            >>>
            >>>>frizzle wrote:
            >>>>
            >>>>
            >>>>>Hi there,
            >>>>>
            >>>>>I have a mySQL system with a news publishing part in it:
            >>>>>Admins can create new items with text in it, and they have an option to
            >>>>>create 'fulltexts', so you'd get "read more ..." on the front page,
            >>>>>click it and read the fulltext.
            >>>>>
            >>>>>Is there a possibility for mySQL (query) to check if 'fulltext' is
            >>>>>empty or not, and only return true or false, so i don't have to put the
            >>>>>whole fulltext into the mysql_fetch_arr ay() to decide wether or not to
            >>>>>show 'read_more', or should i create an extra boolean field in the DB
            >>>>>saying fulltext y/n ?
            >>>>>
            >>>>>Greeting s Frizzle.
            >>>>>
            >>>>
            >>>>Put it in a separate table with just the article's id and the text. If
            >>>>the id exists in the second table, there is more text.
            >>>>
            >>>>--
            >>>>=========== =======
            >>>>Remove the "x" from my email address
            >>>>Jerry Stuckle
            >>>>JDS Computer Training Corp.
            >>>>jstucklex@a ttglobal.net
            >>>>=========== =======
            >>>
            >>>
            >>>This would have me quering against an extra table. Would'nt it be
            >>>quicker to add an extra boolean field then?
            >>>
            >>>Frizzle.
            >>>[/color]
            >>
            >>Why? Joins are quick. Probably a lot faster than unnecessarily
            >>processing empty text fields in the first table.
            >>
            >>--
            >>============= =====
            >>Remove the "x" from my email address
            >>Jerry Stuckle
            >>JDS Computer Training Corp.
            >>jstucklex@att global.net
            >>============= =====[/color]
            >
            >
            > I understand what you're saying. I think i'm underestimating the speed
            > of Joins (mySQL)
            > Not to be a nag, but would it still be faster to add an extra field to
            > the original table, 'fulltext_avail able' tinyint(1), which tells me to
            > look for it or not?
            >
            > And, am i wrong believing that if i use 'SELECT fieldname1, name2 etc.'
            > in the query, it leaves the unmentioned fields unbothered, thus not
            > being influenced by their size/contents ?
            >
            > Frizzle.
            >[/color]

            Yes and no. It depends on the implementation of the database.

            In MySQL, everything in a table is kept in one file. So if you have
            your full text in that table, a table scan will read everything in the
            table and throw away the columns you don't want. If you have a lot of
            text in relation to the rest of the row data, this can be significant
            overhead. If the full text is in a separate table, it will only be read
            when you request information from that table.

            Additionally, is the absolute speed necessary? Are you talking dozens
            (or even hundreds) of queries per second? I doubt it.

            Keeping large amounts of data you only occasionally access is generally
            a better way of doing things. Putting a T/F column in the table just
            makes for another column you have to manage (and violates normalization
            principles).

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • frizzle

              #7
              Re: Return bool from query

              Jerry Stuckle wrote:[color=blue]
              > frizzle wrote:[color=green]
              > > Jerry Stuckle wrote:
              > >[color=darkred]
              > >>frizzle wrote:
              > >>
              > >>>Jerry Stuckle wrote:
              > >>>
              > >>>
              > >>>>frizzle wrote:
              > >>>>
              > >>>>
              > >>>>>Hi there,
              > >>>>>
              > >>>>>I have a mySQL system with a news publishing part in it:
              > >>>>>Admins can create new items with text in it, and they have an option to
              > >>>>>create 'fulltexts', so you'd get "read more ..." on the front page,
              > >>>>>click it and read the fulltext.
              > >>>>>
              > >>>>>Is there a possibility for mySQL (query) to check if 'fulltext' is
              > >>>>>empty or not, and only return true or false, so i don't have to put the
              > >>>>>whole fulltext into the mysql_fetch_arr ay() to decide wether or not to
              > >>>>>show 'read_more', or should i create an extra boolean field in the DB
              > >>>>>saying fulltext y/n ?
              > >>>>>
              > >>>>>Greeting s Frizzle.
              > >>>>>
              > >>>>
              > >>>>Put it in a separate table with just the article's id and the text. If
              > >>>>the id exists in the second table, there is more text.
              > >>>>
              > >>>>--
              > >>>>=========== =======
              > >>>>Remove the "x" from my email address
              > >>>>Jerry Stuckle
              > >>>>JDS Computer Training Corp.
              > >>>>jstucklex@a ttglobal.net
              > >>>>=========== =======
              > >>>
              > >>>
              > >>>This would have me quering against an extra table. Would'nt it be
              > >>>quicker to add an extra boolean field then?
              > >>>
              > >>>Frizzle.
              > >>>
              > >>
              > >>Why? Joins are quick. Probably a lot faster than unnecessarily
              > >>processing empty text fields in the first table.
              > >>
              > >>--
              > >>============= =====
              > >>Remove the "x" from my email address
              > >>Jerry Stuckle
              > >>JDS Computer Training Corp.
              > >>jstucklex@att global.net
              > >>============= =====[/color]
              > >
              > >
              > > I understand what you're saying. I think i'm underestimating the speed
              > > of Joins (mySQL)
              > > Not to be a nag, but would it still be faster to add an extra field to
              > > the original table, 'fulltext_avail able' tinyint(1), which tells me to
              > > look for it or not?
              > >
              > > And, am i wrong believing that if i use 'SELECT fieldname1, name2 etc.'
              > > in the query, it leaves the unmentioned fields unbothered, thus not
              > > being influenced by their size/contents ?
              > >
              > > Frizzle.
              > >[/color]
              >
              > Yes and no. It depends on the implementation of the database.
              >
              > In MySQL, everything in a table is kept in one file. So if you have
              > your full text in that table, a table scan will read everything in the
              > table and throw away the columns you don't want. If you have a lot of
              > text in relation to the rest of the row data, this can be significant
              > overhead. If the full text is in a separate table, it will only be read
              > when you request information from that table.
              >
              > Additionally, is the absolute speed necessary? Are you talking dozens
              > (or even hundreds) of queries per second? I doubt it.
              >
              > Keeping large amounts of data you only occasionally access is generally
              > a better way of doing things. Putting a T/F column in the table just
              > makes for another column you have to manage (and violates normalization
              > principles).
              >
              > --
              > =============== ===
              > Remove the "x" from my email address
              > Jerry Stuckle
              > JDS Computer Training Corp.
              > jstucklex@attgl obal.net
              > =============== ===[/color]

              I don't know (yet) how much queries there will be, but i guess not
              *that* much.
              My lack of english causes me te seize your intention in the last part.
              Do you mean i should put the fulltexts in another extra table?
              I btw hardly doubt if it will be neccesary, since those texts won't be
              that big either.
              (For mySQL / PHP then ... )
              Again, it's a news system, there won't be a whole version of The Da
              Vinci Code behind 'read more'.

              Frizzle.

              Comment

              • bobzimuta

                #8
                Re: Return bool from query

                SELECT IF( CHAR_LENGTH( `text_column` ) > 0, 1, 0 ) AS fulltext_exists
                FROM table WHERE .....

                will return fulltext_exists as 1 if `text_column` has a length greater
                than 0. Otherwise returns 0


                Want to get just the first 50 characters from the fulltext as the
                summary or intro?

                SELECT LEFT( `text_column`, 50 ) AS summary FROM table WHERE ....

                Comment

                • Jerry Stuckle

                  #9
                  Re: Return bool from query

                  frizzle wrote:[color=blue]
                  > Jerry Stuckle wrote:
                  >[color=green]
                  >>frizzle wrote:
                  >>[color=darkred]
                  >>>Jerry Stuckle wrote:
                  >>>
                  >>>
                  >>>>frizzle wrote:
                  >>>>
                  >>>>
                  >>>>>Jerry Stuckle wrote:
                  >>>>>
                  >>>>>
                  >>>>>
                  >>>>>>frizzle wrote:
                  >>>>>>
                  >>>>>>
                  >>>>>>
                  >>>>>>>Hi there,
                  >>>>>>>
                  >>>>>>>I have a mySQL system with a news publishing part in it:
                  >>>>>>>Admins can create new items with text in it, and they have an option to
                  >>>>>>>create 'fulltexts', so you'd get "read more ..." on the front page,
                  >>>>>>>click it and read the fulltext.
                  >>>>>>>
                  >>>>>>>Is there a possibility for mySQL (query) to check if 'fulltext' is
                  >>>>>>>empty or not, and only return true or false, so i don't have to put the
                  >>>>>>>whole fulltext into the mysql_fetch_arr ay() to decide wether or not to
                  >>>>>>>show 'read_more', or should i create an extra boolean field in the DB
                  >>>>>>>saying fulltext y/n ?
                  >>>>>>>
                  >>>>>>>Greeting s Frizzle.
                  >>>>>>>
                  >>>>>>
                  >>>>>>Put it in a separate table with just the article's id and the text. If
                  >>>>>>the id exists in the second table, there is more text.
                  >>>>>>
                  >>>>>>--
                  >>>>>>========= =========
                  >>>>>>Remove the "x" from my email address
                  >>>>>>Jerry Stuckle
                  >>>>>>JDS Computer Training Corp.
                  >>>>>>jstucklex @attglobal.net
                  >>>>>>========= =========
                  >>>>>
                  >>>>>
                  >>>>>This would have me quering against an extra table. Would'nt it be
                  >>>>>quicker to add an extra boolean field then?
                  >>>>>
                  >>>>>Frizzle.
                  >>>>>
                  >>>>
                  >>>>Why? Joins are quick. Probably a lot faster than unnecessarily
                  >>>>processin g empty text fields in the first table.
                  >>>>
                  >>>>--
                  >>>>=========== =======
                  >>>>Remove the "x" from my email address
                  >>>>Jerry Stuckle
                  >>>>JDS Computer Training Corp.
                  >>>>jstucklex@a ttglobal.net
                  >>>>=========== =======
                  >>>
                  >>>
                  >>>I understand what you're saying. I think i'm underestimating the speed
                  >>>of Joins (mySQL)
                  >>>Not to be a nag, but would it still be faster to add an extra field to
                  >>>the original table, 'fulltext_avail able' tinyint(1), which tells me to
                  >>>look for it or not?
                  >>>
                  >>>And, am i wrong believing that if i use 'SELECT fieldname1, name2 etc.'
                  >>>in the query, it leaves the unmentioned fields unbothered, thus not
                  >>>being influenced by their size/contents ?
                  >>>
                  >>>Frizzle.
                  >>>[/color]
                  >>
                  >>Yes and no. It depends on the implementation of the database.
                  >>
                  >>In MySQL, everything in a table is kept in one file. So if you have
                  >>your full text in that table, a table scan will read everything in the
                  >>table and throw away the columns you don't want. If you have a lot of
                  >>text in relation to the rest of the row data, this can be significant
                  >>overhead. If the full text is in a separate table, it will only be read
                  >>when you request information from that table.
                  >>
                  >>Additionall y, is the absolute speed necessary? Are you talking dozens
                  >>(or even hundreds) of queries per second? I doubt it.
                  >>
                  >>Keeping large amounts of data you only occasionally access is generally
                  >>a better way of doing things. Putting a T/F column in the table just
                  >>makes for another column you have to manage (and violates normalization
                  >>principles) .
                  >>
                  >>--
                  >>============= =====
                  >>Remove the "x" from my email address
                  >>Jerry Stuckle
                  >>JDS Computer Training Corp.
                  >>jstucklex@att global.net
                  >>============= =====[/color]
                  >
                  >
                  > I don't know (yet) how much queries there will be, but i guess not
                  > *that* much.
                  > My lack of english causes me te seize your intention in the last part.
                  > Do you mean i should put the fulltexts in another extra table?
                  > I btw hardly doubt if it will be neccesary, since those texts won't be
                  > that big either.
                  > (For mySQL / PHP then ... )
                  > Again, it's a news system, there won't be a whole version of The Da
                  > Vinci Code behind 'read more'.
                  >
                  > Frizzle.
                  >[/color]

                  Yes, I would put the fulltext in a separate table. The join takes very
                  little overhead (since primary keys have an index associated).

                  Very often if you have large amounts of text (several hundred bytes
                  minimum) which you don't always need to access you can save processing
                  time by putting it in its own table.


                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstucklex@attgl obal.net
                  =============== ===

                  Comment

                  • Jerry Stuckle

                    #10
                    Re: Return bool from query

                    frizzle wrote:[color=blue]
                    > Jerry Stuckle wrote:
                    >[color=green]
                    >>frizzle wrote:
                    >>[color=darkred]
                    >>>Jerry Stuckle wrote:
                    >>>
                    >>>
                    >>>>frizzle wrote:
                    >>>>
                    >>>>
                    >>>>>Jerry Stuckle wrote:
                    >>>>>
                    >>>>>
                    >>>>>
                    >>>>>>frizzle wrote:
                    >>>>>>
                    >>>>>>
                    >>>>>>
                    >>>>>>>Hi there,
                    >>>>>>>
                    >>>>>>>I have a mySQL system with a news publishing part in it:
                    >>>>>>>Admins can create new items with text in it, and they have an option to
                    >>>>>>>create 'fulltexts', so you'd get "read more ..." on the front page,
                    >>>>>>>click it and read the fulltext.
                    >>>>>>>
                    >>>>>>>Is there a possibility for mySQL (query) to check if 'fulltext' is
                    >>>>>>>empty or not, and only return true or false, so i don't have to put the
                    >>>>>>>whole fulltext into the mysql_fetch_arr ay() to decide wether or not to
                    >>>>>>>show 'read_more', or should i create an extra boolean field in the DB
                    >>>>>>>saying fulltext y/n ?
                    >>>>>>>
                    >>>>>>>Greeting s Frizzle.
                    >>>>>>>
                    >>>>>>
                    >>>>>>Put it in a separate table with just the article's id and the text. If
                    >>>>>>the id exists in the second table, there is more text.
                    >>>>>>
                    >>>>>>--
                    >>>>>>========= =========
                    >>>>>>Remove the "x" from my email address
                    >>>>>>Jerry Stuckle
                    >>>>>>JDS Computer Training Corp.
                    >>>>>>jstucklex @attglobal.net
                    >>>>>>========= =========
                    >>>>>
                    >>>>>
                    >>>>>This would have me quering against an extra table. Would'nt it be
                    >>>>>quicker to add an extra boolean field then?
                    >>>>>
                    >>>>>Frizzle.
                    >>>>>
                    >>>>
                    >>>>Why? Joins are quick. Probably a lot faster than unnecessarily
                    >>>>processin g empty text fields in the first table.
                    >>>>
                    >>>>--
                    >>>>=========== =======
                    >>>>Remove the "x" from my email address
                    >>>>Jerry Stuckle
                    >>>>JDS Computer Training Corp.
                    >>>>jstucklex@a ttglobal.net
                    >>>>=========== =======
                    >>>
                    >>>
                    >>>I understand what you're saying. I think i'm underestimating the speed
                    >>>of Joins (mySQL)
                    >>>Not to be a nag, but would it still be faster to add an extra field to
                    >>>the original table, 'fulltext_avail able' tinyint(1), which tells me to
                    >>>look for it or not?
                    >>>
                    >>>And, am i wrong believing that if i use 'SELECT fieldname1, name2 etc.'
                    >>>in the query, it leaves the unmentioned fields unbothered, thus not
                    >>>being influenced by their size/contents ?
                    >>>
                    >>>Frizzle.
                    >>>[/color]
                    >>
                    >>Yes and no. It depends on the implementation of the database.
                    >>
                    >>In MySQL, everything in a table is kept in one file. So if you have
                    >>your full text in that table, a table scan will read everything in the
                    >>table and throw away the columns you don't want. If you have a lot of
                    >>text in relation to the rest of the row data, this can be significant
                    >>overhead. If the full text is in a separate table, it will only be read
                    >>when you request information from that table.
                    >>
                    >>Additionall y, is the absolute speed necessary? Are you talking dozens
                    >>(or even hundreds) of queries per second? I doubt it.
                    >>
                    >>Keeping large amounts of data you only occasionally access is generally
                    >>a better way of doing things. Putting a T/F column in the table just
                    >>makes for another column you have to manage (and violates normalization
                    >>principles) .
                    >>
                    >>--
                    >>============= =====
                    >>Remove the "x" from my email address
                    >>Jerry Stuckle
                    >>JDS Computer Training Corp.
                    >>jstucklex@att global.net
                    >>============= =====[/color]
                    >
                    >
                    > I don't know (yet) how much queries there will be, but i guess not
                    > *that* much.
                    > My lack of english causes me te seize your intention in the last part.
                    > Do you mean i should put the fulltexts in another extra table?
                    > I btw hardly doubt if it will be neccesary, since those texts won't be
                    > that big either.
                    > (For mySQL / PHP then ... )
                    > Again, it's a news system, there won't be a whole version of The Da
                    > Vinci Code behind 'read more'.
                    >
                    > Frizzle.
                    >[/color]


                    I should also add - something like

                    SELECT COUNT(id) FROM texttable WHERE id=1;

                    is quite quick. Chances are since id is a primary key, MySQL won't even
                    go to the table itself - it will just see if it exists in the index.


                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstucklex@attgl obal.net
                    =============== ===

                    Comment

                    • Steve

                      #11
                      Re: Return bool from query

                      On Tue, 07 Feb 2006 14:42:57 -0800, frizzle wrote:
                      [color=blue]
                      > Jerry Stuckle wrote:[color=green]
                      >> frizzle wrote:[color=darkred]
                      >> > Jerry Stuckle wrote:
                      >> >
                      >> >>frizzle wrote:
                      >> >>
                      >> >>>Jerry Stuckle wrote:
                      >> >>>
                      >> >>>
                      >> >>>>frizzle wrote:
                      >> >>>>
                      >> >>>>
                      >> >>>>>Hi there,
                      >> >>>>>
                      >> >>>>>I have a mySQL system with a news publishing part in it:
                      >> >>>>>Admins can create new items with text in it, and they have an option to
                      >> >>>>>create 'fulltexts', so you'd get "read more ..." on the front page,
                      >> >>>>>click it and read the fulltext.
                      >> >>>>>
                      >> >>>>>Is there a possibility for mySQL (query) to check if 'fulltext' is
                      >> >>>>>empty or not, and only return true or false, so i don't have to put the
                      >> >>>>>whole fulltext into the mysql_fetch_arr ay() to decide wether or not to
                      >> >>>>>show 'read_more', or should i create an extra boolean field in the DB
                      >> >>>>>saying fulltext y/n ?
                      >> >>>>>
                      >> >>>>>Greeting s Frizzle.
                      >> >>>>>
                      >> >>>>
                      >> >>>>Put it in a separate table with just the article's id and the text. If
                      >> >>>>the id exists in the second table, there is more text.
                      >> >>>>
                      >> >>>>--
                      >> >>>>=========== =======
                      >> >>>>Remove the "x" from my email address
                      >> >>>>Jerry Stuckle
                      >> >>>>JDS Computer Training Corp.
                      >> >>>>jstucklex@a ttglobal.net
                      >> >>>>=========== =======
                      >> >>>
                      >> >>>
                      >> >>>This would have me quering against an extra table. Would'nt it be
                      >> >>>quicker to add an extra boolean field then?
                      >> >>>
                      >> >>>Frizzle.
                      >> >>>
                      >> >>
                      >> >>Why? Joins are quick. Probably a lot faster than unnecessarily
                      >> >>processing empty text fields in the first table.
                      >> >>
                      >> >>--
                      >> >>============= =====
                      >> >>Remove the "x" from my email address
                      >> >>Jerry Stuckle
                      >> >>JDS Computer Training Corp.
                      >> >>jstucklex@att global.net
                      >> >>============= =====
                      >> >
                      >> >
                      >> > I understand what you're saying. I think i'm underestimating the speed
                      >> > of Joins (mySQL)
                      >> > Not to be a nag, but would it still be faster to add an extra field to
                      >> > the original table, 'fulltext_avail able' tinyint(1), which tells me to
                      >> > look for it or not?
                      >> >
                      >> > And, am i wrong believing that if i use 'SELECT fieldname1, name2 etc.'
                      >> > in the query, it leaves the unmentioned fields unbothered, thus not
                      >> > being influenced by their size/contents ?
                      >> >
                      >> > Frizzle.
                      >> >[/color]
                      >>
                      >> Yes and no. It depends on the implementation of the database.
                      >>
                      >> In MySQL, everything in a table is kept in one file. So if you have
                      >> your full text in that table, a table scan will read everything in the
                      >> table and throw away the columns you don't want. If you have a lot of
                      >> text in relation to the rest of the row data, this can be significant
                      >> overhead. If the full text is in a separate table, it will only be read
                      >> when you request information from that table.
                      >>
                      >> Additionally, is the absolute speed necessary? Are you talking dozens
                      >> (or even hundreds) of queries per second? I doubt it.
                      >>
                      >> Keeping large amounts of data you only occasionally access is generally
                      >> a better way of doing things. Putting a T/F column in the table just
                      >> makes for another column you have to manage (and violates normalization
                      >> principles).
                      >>
                      >> --
                      >> =============== ===
                      >> Remove the "x" from my email address
                      >> Jerry Stuckle
                      >> JDS Computer Training Corp.
                      >> jstucklex@attgl obal.net
                      >> =============== ===[/color]
                      >
                      > I don't know (yet) how much queries there will be, but i guess not
                      > *that* much.
                      > My lack of english causes me te seize your intention in the last part.
                      > Do you mean i should put the fulltexts in another extra table?
                      > I btw hardly doubt if it will be neccesary, since those texts won't be
                      > that big either.
                      > (For mySQL / PHP then ... )
                      > Again, it's a news system, there won't be a whole version of The Da
                      > Vinci Code behind 'read more'.
                      >
                      > Frizzle.[/color]

                      Always normalise your data model first. Then, if it isn't fast enough, add
                      in shortcuts. Databases ( even mysql (: ) are really powerful - but that
                      also means that you can really screw everything up if you don't stand back
                      first, and get a proper idea of what you're trying to do first.

                      There must be a copy of C.J.Date on the internet somewhere - it must be 30
                      years old by now.

                      Steve

                      Comment

                      • pjSoni

                        #12
                        Re: Return bool from query

                        Hi

                        Try to do like when admin enters article he should enter <SPLIT> tag
                        from where you want break with article so when you read from db try to
                        split from split tag.

                        Regards,
                        Jatin

                        Comment

                        • frizzle

                          #13
                          Re: Return bool from query

                          pjSoni wrote:[color=blue]
                          > Hi
                          >
                          > Try to do like when admin enters article he should enter <SPLIT> tag
                          > from where you want break with article so when you read from db try to
                          > split from split tag.
                          >
                          > Regards,
                          > Jatin[/color]

                          Thanks all for the replies.
                          I understand what bobzimuta and pjSoni are saying with the intro thing,
                          but i need two different fields, so the intro in the fulltext can
                          differ from just te intro.

                          I think i'll go with Jerry's: SELECT COUNT(id) FROM texttable WHERE
                          id=1;
                          But the id of the fulltext would have to match the exact id of the
                          record with intro and other info?
                          Would it matter if i added LIMIT 1 to it, so the DB won't go on?

                          How careful should i be asigning extra indexes? I read somewhere, that
                          if i asign indexes to fields that aren't going te be updated a lot,
                          it's not bad, otherwise it would take a lot of time ...

                          And now i also have second thoughts about my field in the topic records
                          with the number of replies.
                          It goes against normalization, but i thought it would save a lot of
                          calculating time ...

                          Frizzle.

                          Comment

                          • Jerry Stuckle

                            #14
                            Re: Return bool from query

                            frizzle wrote:[color=blue]
                            > pjSoni wrote:
                            >[color=green]
                            >>Hi
                            >>
                            >>Try to do like when admin enters article he should enter <SPLIT> tag
                            >>from where you want break with article so when you read from db try to
                            >>split from split tag.
                            >>
                            >>Regards,
                            >>Jatin[/color]
                            >
                            >
                            > Thanks all for the replies.
                            > I understand what bobzimuta and pjSoni are saying with the intro thing,
                            > but i need two different fields, so the intro in the fulltext can
                            > differ from just te intro.
                            >
                            > I think i'll go with Jerry's: SELECT COUNT(id) FROM texttable WHERE
                            > id=1;
                            > But the id of the fulltext would have to match the exact id of the
                            > record with intro and other info?
                            > Would it matter if i added LIMIT 1 to it, so the DB won't go on?
                            >
                            > How careful should i be asigning extra indexes? I read somewhere, that
                            > if i asign indexes to fields that aren't going te be updated a lot,
                            > it's not bad, otherwise it would take a lot of time ...
                            >
                            > And now i also have second thoughts about my field in the topic records
                            > with the number of replies.
                            > It goes against normalization, but i thought it would save a lot of
                            > calculating time ...
                            >
                            > Frizzle.
                            >[/color]

                            Yes, it has to match the key of the other table. It would also the
                            primary key of that entry. Being a primary key, it would be unique.

                            Also, if your use INNODB tables you can make it a foreign key
                            referencing the other table.

                            You shouldn't need to add LIMIT 1 to the query because you have a unique
                            index on the field. MySQL should be able to fetch everything it needs
                            from the index (which, unlike the table, is in order).

                            --
                            =============== ===
                            Remove the "x" from my email address
                            Jerry Stuckle
                            JDS Computer Training Corp.
                            jstucklex@attgl obal.net
                            =============== ===

                            Comment

                            • frizzle

                              #15
                              Re: Return bool from query

                              Jerry Stuckle wrote:[color=blue]
                              > frizzle wrote:[color=green]
                              > > pjSoni wrote:
                              > >[color=darkred]
                              > >>Hi
                              > >>
                              > >>Try to do like when admin enters article he should enter <SPLIT> tag
                              > >>from where you want break with article so when you read from db try to
                              > >>split from split tag.
                              > >>
                              > >>Regards,
                              > >>Jatin[/color]
                              > >
                              > >
                              > > Thanks all for the replies.
                              > > I understand what bobzimuta and pjSoni are saying with the intro thing,
                              > > but i need two different fields, so the intro in the fulltext can
                              > > differ from just te intro.
                              > >
                              > > I think i'll go with Jerry's: SELECT COUNT(id) FROM texttable WHERE
                              > > id=1;
                              > > But the id of the fulltext would have to match the exact id of the
                              > > record with intro and other info?
                              > > Would it matter if i added LIMIT 1 to it, so the DB won't go on?
                              > >
                              > > How careful should i be asigning extra indexes? I read somewhere, that
                              > > if i asign indexes to fields that aren't going te be updated a lot,
                              > > it's not bad, otherwise it would take a lot of time ...
                              > >
                              > > And now i also have second thoughts about my field in the topic records
                              > > with the number of replies.
                              > > It goes against normalization, but i thought it would save a lot of
                              > > calculating time ...
                              > >
                              > > Frizzle.
                              > >[/color]
                              >
                              > Yes, it has to match the key of the other table. It would also the
                              > primary key of that entry. Being a primary key, it would be unique.
                              >
                              > Also, if your use INNODB tables you can make it a foreign key
                              > referencing the other table.
                              >
                              > You shouldn't need to add LIMIT 1 to the query because you have a unique
                              > index on the field. MySQL should be able to fetch everything it needs
                              > from the index (which, unlike the table, is in order).
                              >
                              > --
                              > =============== ===
                              > Remove the "x" from my email address
                              > Jerry Stuckle
                              > JDS Computer Training Corp.
                              > jstucklex@attgl obal.net
                              > =============== ===[/color]

                              Why is this unlike the table in order? Since both are probably created
                              in the same instance. The Fulltext indexes have a bigger chance *not*
                              to be in order, since they could be added later ...

                              And what exactly do you mean with a foreign key ?

                              Frizzle.

                              (Thanks a lot for your effort to help me!)

                              Comment

                              Working...