473,729 Members | 2,150 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.

Feb 7 '06
25 2261
On Tue, 07 Feb 2006 14:42:57 -0800, frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
> 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.
>>>>js*******@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.
>>js*******@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.
>


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.
js*******@attgl obal.net
=============== ===


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.


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

Feb 8 '06 #11
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

Feb 8 '06 #12
pjSoni wrote:
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


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.

Feb 8 '06 #13
frizzle wrote:
pjSoni wrote:
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

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.


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.
js*******@attgl obal.net
=============== ===
Feb 8 '06 #14
Jerry Stuckle wrote:
frizzle wrote:
pjSoni wrote:
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

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.


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.
js*******@attgl obal.net
=============== ===


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!)

Feb 8 '06 #15
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:
pjSoni wrote:
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
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
calculatin g time ...

Frizzle.


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.
js*******@att global.net
============= =====

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!)


First of all, check out foreign keys in the MySQL documentation:
http://dev.mysql.com/doc/refman/5.0/...eign-keys.html

No, the table wouldn't necessarily be in order (your original one
wouldn't either - SQL is by default unordered). But the index built on
the primary key is always ordered (so the engine can do a quick binary
search of the index). Therefore, MySQL can determine whether a record
exists or not by searching the index and doesn't need to load the file
itself in the query I showed you.

But the advantage is you wouldn't have to read the full text data every
time you need to access the summary information. You only get the full
text when you request it.

Remember - MySQL reads the entire row, even if you only ask for part of
the data, because everything's in one file.

Also, if you have a request which requires a full table scan, having the
full text in a separate table improves the table scan (unless, of
course, you're searching the full text data).
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Feb 8 '06 #16
Jerry Stuckle wrote:
frizzle wrote:
Jerry Stuckle wrote:
frizzle wrote:

pjSoni wrote:
>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
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
calculatin g time ...

Frizzle.
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.
js*******@att global.net
============= =====

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!)


First of all, check out foreign keys in the MySQL documentation:
http://dev.mysql.com/doc/refman/5.0/...eign-keys.html

No, the table wouldn't necessarily be in order (your original one
wouldn't either - SQL is by default unordered). But the index built on
the primary key is always ordered (so the engine can do a quick binary
search of the index). Therefore, MySQL can determine whether a record
exists or not by searching the index and doesn't need to load the file
itself in the query I showed you.

But the advantage is you wouldn't have to read the full text data every
time you need to access the summary information. You only get the full
text when you request it.

Remember - MySQL reads the entire row, even if you only ask for part of
the data, because everything's in one file.

Also, if you have a request which requires a full table scan, having the
full text in a separate table improves the table scan (unless, of
course, you're searching the full text data).
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===


Ok, thanks a lot, you convinced me on this. This of course is quite
important for more other things to achieve. I will for instance not
save the number of comments as an int() in the topics table, but will
perform a count!

Frizzle.

Feb 8 '06 #17
I am btw not using INNODB, but ISAM.
(Neither ring a bell for me, but that's what the docs said.)

Frizzle.

Feb 8 '06 #18
frizzle wrote:
I am btw not using INNODB, but ISAM.
(Neither ring a bell for me, but that's what the docs said.)

Frizzle.


If you're going to use foreign keys, you need to change to innodb. It's
not hard - just call ALTER TABLE on each one.

Or use PHPMyAdmin - a great tool if you're not familiar with it.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Feb 8 '06 #19
Jerry Stuckle wrote:
frizzle wrote:
I am btw not using INNODB, but ISAM.
(Neither ring a bell for me, but that's what the docs said.)

Frizzle.


If you're going to use foreign keys, you need to change to innodb. It's
not hard - just call ALTER TABLE on each one.

Or use PHPMyAdmin - a great tool if you're not familiar with it.

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


I actually use PHPmyAdmin, but don't know where to set it to INNODB, or
my host disabled that, (i can choose form 3 other ones though ...)

Frizzle.

Feb 8 '06 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
2155
by: John Bailo | last post by:
The c# *return* statement has been bothering me the past few months. I don't like the fact that you can have different code paths in a method and have multiple return statements. To me, it would be more orthogonal if a method could only have one return statement. --
2
5361
by: Justin Dutoit | last post by:
Hey. I have a function with a boolean return value, called IsInWarehouse, which checks if a product is available in a warehouse, or not. But I need security in the function too, so I have public bool IsInWarehouse(string productName) { if (Login(username, password)) { // query db about available product } else {
10
19158
by: Mark Jerde | last post by:
I'm trying to learn the very basics of using an unmanaged C++ DLL from C#. This morning I thought I was getting somewhere, successfully getting back the correct answers to a C++ " int SumArray(int ray, int count)" Now I'm having problems with C++ "return(false)" being True in C#. Here is the C# code. ========================= using System; using System.Runtime.InteropServices; //
5
2067
by: Edward Diener | last post by:
I am gathering from the documentation that return values from __events are not illegal but are frowned upon in .NET. If this is the case, does one pass back values from an event handler via "in/out" or "out" parameters ? Or is it simply that events are just notifications and are not interested in any values which event handlers might be able to return ? If the latter is the case, the event model in .NET appears to have a great...
3
1920
by: Daves | last post by:
a get { ... } for public property SelectedValue returns DateTime type to be used as a parameter in a Sql update query but I'd like it to return "empty" if no date has been selected... I cannot use return null; because "Cannot convert null to 'System.DateTime' because it is a value type" How can this be done?
40
3142
by: Mark P | last post by:
I'm implementing an algorithm and the computational flow is a somewhat deep. That is, fcn A makes many calls to fcn B which makes many calls to fcn C, and so on. The return value of the outermost fcn is a boolean and there are certain places within the inner functions where it may become apparent that the return value is false. In this case I'd like to halt the computation immediately and return false. My current approach is to have...
2
27066
by: fhasdkfhadlksfjhalsdkfh12 | last post by:
I've been working on a decryption program for another encryption program I made. It isn't finished, and when I try to compile it to test it, it gives me the error "expected unqualified-id before 'return'" right at the line where "return 0;" is. I am using Xcode for mac os, which is the same as g++ 4.0 for Unix/Linux. I can't seem to figure this out, and I can't test anything until it's fixed. Any ideas? Here's the code:...
13
2907
by: cppquester | last post by:
A colleague told me that there is a rule about good stype that a function in C++ should have only one point of return (ie. return statement). Otherwise there might be trouble. I never heard about it and doubt it. Anybody heard of it? What would be the advantage? Regards, Marc Example:
6
1830
by: exander77 | last post by:
I am quite new to c++, about half of a year. I juct wonder, why such code is not possible: int chlen(char * ar) { for(int i=0;ar||return i;i++); } In my opinion, it would be much "cuter" than this: int chlen(char * ar) {
0
8913
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6016
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2162
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.