<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-NZ link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Hi Steve<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I read your original email again and note:<o:p></o:p></span></p><p class=MsoNormal><i>My understanding is that this will never be indexed, even if you specifically add an index to it. So how do you handle it. There may be several boolean fields in a table definition.<o:p></o:p></i></p><p class=MsoNormal><i><o:p> </o:p></i></p><p class=MsoNormal><i>As these tables can contain several hundred thousand records, this could potentially slow down any query to say total all records last 3 years where Active and Income - as the only index would then be on the date field, there is a possibility that this could potentially be a very slow query.<o:p></o:p></i></p><p class=MsoNormal><i><o:p> </o:p></i></p><p class=MsoNormal><i>I've heard of others creating another table to create, say, non-Avtive record ID's, but this one table could have several booleans, therefore creating several new tables (combining then into a single table with the field name would cause the same problem).<o:p></o:p></i></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I am trying to interpret for myself what your concern is. Indexing and using Booleans in tables, resulting in slow queries?<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>You have a general concern without a specific example. You understanding about something “never indexed” is not clear to me. Maybe you have in mind that an optimiser will not use some indices because an index has a Boolean in it? <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>One way to respond to your concern is to discuss index selectivity and optimisers. I won’t do this as I don’t know enough about the FB query optimiser. So I’ll respond pragmatically. I am using Booleans in many tables and in many queries in software with biggest table 600,000 records and 400MB+ DB file sizes. In FB 2.5.x. To the best of my knowledge I do not have slow query problems with Booleans.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>If you have slow queries there are options to look at. We’d need to get specific. I would not let a concern for using Booleans worry me. <o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I hope I have understood you in a reasonable sense…<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Kind regards,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Russell<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> delphi-bounces@listserver.123.net.nz [mailto:delphi-bounces@listserver.123.net.nz] <b>On Behalf Of </b>Steve Peacocke<br><b>Sent:</b> Monday, 31 March 2014 9:15 a.m.<br><b>To:</b> NZ Borland Developers Group - Delphi List<br><b>Subject:</b> Re: [DUG] Using Boolean (Char(1)) in Firebird<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>Thanks Jolyon,<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Silly me, I thought this was going to be simple.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Add Index, don't add index, it's a Boolean decision, I never expected NULL as an answer :)<o:p></o:p></p></div><div><div><p class=MsoNormal><br>Steve Peacocke<br>Mobile: +64 220 612-611<o:p></o:p></p><div><div><p class=MsoNormal><a href="http://nz.linkedin.com/pub/steve-peacocke/1/a06/489" target="_blank">Linkedin Professional Profile</a><o:p></o:p></p></div></div></div><p class=MsoNormal style='margin-bottom:12.0pt'><o:p> </o:p></p><div><p class=MsoNormal>On Mon, Mar 31, 2014 at 8:56 AM, Jolyon Smith <<a href="mailto:jsmith@deltics.co.nz" target="_blank">jsmith@deltics.co.nz</a>> wrote:<o:p></o:p></p><div><p class=MsoNormal style='margin-bottom:12.0pt'>I don't think you can adopt a general rule for all boolean type conditions in data. In the two example fields you cite, for example, I can see that there is a potential difference in the nature of the booleans involved.<o:p></o:p></p><p class=MsoNormal>ActiveRecord - looks like something that could change over time. A record that was active may become inactive and I further speculate that there will over time be far more inactive records than active ones.<br><br>AccountTransactionType - looks like something that is fixed. The type of a transaction seems unlikely to change once that transaction has been recorded. You might call this a "static" boolean, as opposed to the more "dynamic" nature of the previous example.<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Of course, more specific domain knowledge may reveal these assumptions to be invalid, but you get the general idea.... the characteristics of a particular datum go beyond it's simple data type and those characteristics in turn determine the most appropriate implementation (which in turn will depend on whether the dominant context is OLTP or OLAP - i.e. efficiency of creating/modifying data vs efficiency of queries).<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>In the case of "static" booleans for example, you might consider creating separate tables for records of different values in this field. For convenience of querying all records you can of course project a view which unions the two (or more) tables involved, with a derived, virtual column containing the discriminating field value. This also opens up the possibility that the most efficient indexes for rows of a certain type (i.e. now table) may well be different than those for the other. i.e. the way you work with Income transactions might benefit from different indexes than Expense transactions.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>On the other hand, the way you work with income and expense transactions may mean that you are better off having indexes operating over ALL transactions, regardless of Income/Expense type.<br><br>See what I mean about "the best way" being dependent on far more than just the data type ?<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>And there's still more to it than that...<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>w.r.t index selectivity, I am not convinced that the 1 / # of distinct values metric is a particularly reliable measure. It surely assumes an even distribution of distinct values across the data set ?<o:p></o:p></p></div><div><p class=MsoNormal style='margin-bottom:12.0pt'><br>i.e. if you have 100,000 records and they have a column where 50,000 rows have one value and 50,000 have another, then yes, the efficiency and thus the utility of any index on that value is going to be negligible (but then, no better than having no index isn't actually *worse*, is it ? Although there will be some overhead introduced in maintaining the index, though I doubt this will itself be hugely significant).<br><br>On the other hand, if only 1,000 of those 100,000 records have one value and the remaining 99,000 have another, AND if your application most often queries that table to select those in the smaller subset (the 1,000) then whilst an index may not be of any benefit for querying the 99,000, it surely will provide benefit for those queries that select the 1,000 (or from among them), a benefit which *might* be worth the overhead of maintaining that index even though it provides little/no benefit for the handful/minority of queries that work with the 99,000 records ?<br><br><o:p></o:p></p></div><div><div><p class=MsoNormal>The bottom line is, there is no shortcut for properly understanding your data and the way your application(s) work(s) with that data for correctly tuning your database structure and metadata for optimal performance.<o:p></o:p></p></div></div><div><p class=MsoNormal><br>:)<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p><div><div><div><p class=MsoNormal>On 30 March 2014 15:19, Steve Peacocke <<a href="mailto:steve@peacocke.net" target="_blank">steve@peacocke.net</a>> wrote:<o:p></o:p></p></div></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm'><div><div><div><p class=MsoNormal>Hi all,<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>I'm playing around with a Firebird database and wanted to know from you DB experts out there how you handle booleans in a table.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>These could be as simple as<o:p></o:p></p></div><div><p class=MsoNormal> ActiveRecord (Y/N)<o:p></o:p></p></div><div><p class=MsoNormal> AccountTransactionType (I/E) - (Income or Expense)<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>That last I would normally think would be "Income (Y/N)" so that would be a boolean too.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>My understanding is that this will never be indexed, even if you specifically add an index to it. So how do you handle it. There may be several boolean fields in a table definition.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>As these tables c an contain several hundred thousand records, this could potentially slow down any query to say total all records last 3 years where Active and Income - as the only index would then be on the date field, there is a possibility that this could potentially be a very slow query.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>I've heard of others creating another table to create, say, non-Avtive record ID's, but this one table could have several booleans, therefore creating several new tables (combining then into a single table with the field name would cause the same problem).<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Any thoughts?<span style='color:#888888'><br clear=all><o:p></o:p></span></p><div><p class=MsoNormal><span style='color:#888888'><br>Steve Peacocke<br>Mobile: <a href="tel:%2B64%20220%20612-611" target="_blank">+64 220 612-611</a><o:p></o:p></span></p><div><div><p class=MsoNormal><span style='color:#888888'><a href="http://nz.linkedin.com/pub/steve-peacocke/1/a06/489" target="_blank">Linkedin Professional Profile</a><o:p></o:p></span></p></div></div></div></div></div><p class=MsoNormal><o:p> </o:p></p></div></div><div><p class=MsoNormal>_______________________________________________<br>NZ Borland Developers Group - Delphi mailing list<br>Post: <a href="mailto:delphi@listserver.123.net.nz" target="_blank">delphi@listserver.123.net.nz</a><br>Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz" target="_blank">delphi-request@listserver.123.net.nz</a> with Subject: unsubscribe<o:p></o:p></p></div></blockquote></div><p class=MsoNormal><o:p> </o:p></p></div></div><p class=MsoNormal><br>_______________________________________________<br>NZ Borland Developers Group - Delphi mailing list<br>Post: <a href="mailto:delphi@listserver.123.net.nz">delphi@listserver.123.net.nz</a><br>Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi" target="_blank">http://delphi.org.nz/mailman/listinfo/delphi</a><br>Unsubscribe: send an email to <a href="mailto:delphi-request@listserver.123.net.nz">delphi-request@listserver.123.net.nz</a> with Subject: unsubscribe<o:p></o:p></p></div><p class=MsoNormal><o:p> </o:p></p></div></div></div></body></html>