Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > Oracle Database

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-23-2008, 09:47 AM
kuntz.1507173@bloglines.com
 
Posts: n/a
Default Fast bitwise search

Hi,

we have a large table that contains a bitmask field:

CREATE TABLE A (
ID NUMBER(15),
......
MASK NUMBER(19)
)

The application then performs a query that includes BITAND(MASK, ?) > 0
condition.

Is there any way to use an index for this condition. I was thinking
about bitmap indexes for this but could not figure out how to use them
here.

Can anyone help?

Thank you,
Alex Kuntz.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-23-2008, 09:47 AM
Richard Kuhler
 
Posts: n/a
Default Re: Fast bitwise search

kuntz.1507173@bloglines.com wrote:
> we have a large table that contains a bitmask field:
> MASK NUMBER(19)
>
> The application then performs a query that includes BITAND(MASK, ?) > 0
> condition.
>
> Is there any way to use an index for this condition. I was thinking
> about bitmap indexes for this but could not figure out how to use them
> here.


Why in the world would you bundle data up into a column like that? I
can't imagine why the correct solution isn't to break those bits out
into individual columns with descriptive names so people can actually
see what information is stored there. Then you could use bitmap indexes
on them if performance dictated it (keeping in mind the problems they
create).

--
Richard Kuhler

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-23-2008, 09:48 AM
Frank van Bortel
 
Posts: n/a
Default Re: Fast bitwise search

Richard Kuhler wrote:
> kuntz.1507173@bloglines.com wrote:
>
>> we have a large table that contains a bitmask field:
>> MASK NUMBER(19)
>>
>> The application then performs a query that includes BITAND(MASK, ?) > 0
>> condition.
>>
>> Is there any way to use an index for this condition. I was thinking
>> about bitmap indexes for this but could not figure out how to use them
>> here.

>
>
> Why in the world would you bundle data up into a column like that? I
> can't imagine why the correct solution isn't to break those bits out
> into individual columns with descriptive names so people can actually
> see what information is stored there. Then you could use bitmap indexes
> on them if performance dictated it (keeping in mind the problems they
> create).
>
> --
> Richard Kuhler
>


Why would Oracle use this internally all over? (Check sql.bsq).
For one, you can add a new mask, without adding columns to
the design.
--

Regards,
Frank van Bortel

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-23-2008, 09:48 AM
Richard Kuhler
 
Posts: n/a
Default Re: Fast bitwise search

Frank van Bortel wrote:
> Richard Kuhler wrote:
>
>> kuntz.1507173@bloglines.com wrote:
>>
>>> we have a large table that contains a bitmask field:
>>> MASK NUMBER(19)
>>>
>>> The application then performs a query that includes BITAND(MASK, ?) > 0
>>> condition.
>>>
>>> Is there any way to use an index for this condition. I was thinking
>>> about bitmap indexes for this but could not figure out how to use them
>>> here.

>>
>> Why in the world would you bundle data up into a column like that? I
>> can't imagine why the correct solution isn't to break those bits out
>> into individual columns with descriptive names so people can actually
>> see what information is stored there. Then you could use bitmap
>> indexes on them if performance dictated it (keeping in mind the
>> problems they create).
>>
>> --
>> Richard Kuhler

>
> Why would Oracle use this internally all over? (Check sql.bsq).
> For one, you can add a new mask, without adding columns to
> the design.


No offense, but if you mimic everything I've seen done by Oracle's own
developers then you're going to make many mistakes. They aren't gods.
In fact, why not just have one table with one BLOB column, store
everything in that and we'd never have to change the data model again?
STOP! I'm not suggesting you do that! (although I've seen it done with
disastrous results). The reason is that it defeats one of the major
purposes of having a data model. Namely, so that data is stored in a
well-described manner so a wide variety of people can access it
intuitively and easily. This bitmask scenario is extremely counter to that.

Besides, why is adding columns to a table to support new functionality a
bad thing? Heaven forbid it might actually work to inform people that
it exists.

--
Richard Kuhler

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-23-2008, 09:48 AM
ctcgag@hotmail.com
 
Posts: n/a
Default Re: Fast bitwise search

Richard Kuhler <noone@nowhere.com> wrote:
> kuntz.1507173@bloglines.com wrote:
> > we have a large table that contains a bitmask field:
> > MASK NUMBER(19)
> >
> > The application then performs a query that includes BITAND(MASK, ?) > 0
> > condition.
> >
> > Is there any way to use an index for this condition. I was thinking
> > about bitmap indexes for this but could not figure out how to use them
> > here.

>
> Why in the world would you bundle data up into a column like that? I
> can't imagine why the correct solution isn't to break those bits out
> into individual columns with descriptive names so people can actually
> see what information is stored there. Then you could use bitmap indexes
> on them if performance dictated it (keeping in mind the problems they
> create).


I don't know why the OP would bundle data up like that, but I do it because
N+512 columns in a table is just too many, and N+2048 columns is way too
many. (Of course, I have little hopes of getting bitmap indices to work
effectively on this data anyway.)

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-23-2008, 09:48 AM
Richard Kuhler
 
Posts: n/a
Default Re: Fast bitwise search

ctcgag@hotmail.com wrote:
> Richard Kuhler <noone@nowhere.com> wrote:
>
>>kuntz.1507173@bloglines.com wrote:
>>
>>>we have a large table that contains a bitmask field:
>>>MASK NUMBER(19)
>>>
>>>The application then performs a query that includes BITAND(MASK, ?) > 0
>>>condition.
>>>
>>>Is there any way to use an index for this condition. I was thinking
>>>about bitmap indexes for this but could not figure out how to use them
>>>here.

>>
>>Why in the world would you bundle data up into a column like that? I
>>can't imagine why the correct solution isn't to break those bits out
>>into individual columns with descriptive names so people can actually
>>see what information is stored there. Then you could use bitmap indexes
>>on them if performance dictated it (keeping in mind the problems they
>>create).

>
> I don't know why the OP would bundle data up like that, but I do it because
> N+512 columns in a table is just too many, and N+2048 columns is way too
> many. (Of course, I have little hopes of getting bitmap indices to work
> effectively on this data anyway.)
>
> Xho


Wow, you really have a tuple with 2048 distinct and meaningful
attributes? What is this application if I might ask? Even if you
convinced me that they absolutely can't be columns, I'd wonder why they
can't be rows in a related table.

--
Richard Kuhler


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-23-2008, 09:49 AM
Connor McDonald
 
Posts: n/a
Default Re: Fast bitwise search

Richard Kuhler wrote:
>
> kuntz.1507173@bloglines.com wrote:
> > we have a large table that contains a bitmask field:
> > MASK NUMBER(19)
> >
> > The application then performs a query that includes BITAND(MASK, ?) > 0
> > condition.
> >
> > Is there any way to use an index for this condition. I was thinking
> > about bitmap indexes for this but could not figure out how to use them
> > here.

>
> Why in the world would you bundle data up into a column like that? I
> can't imagine why the correct solution isn't to break those bits out
> into individual columns with descriptive names so people can actually
> see what information is stored there. Then you could use bitmap indexes
> on them if performance dictated it (keeping in mind the problems they
> create).
>
> --
> Richard Kuhler


Lets says its 20 attributes, each being boolean. A b-tree index isn't
going to help since the cardinality is so low. Bitmap indexes pretty
much mean that the table has to be read-only. Moving the attributes to
rows might not work so well since may end up with a massive lot of joins
to the attribute table to handle the various AND/OR permutations.

So you might indeed be up for a full scan no matter what, at which
point, a bit mask in a single column may indeed be the best way to go

Cheers
Connor
--
Connor McDonald
Co-author: "Mastering Oracle PL/SQL - Practical Solutions"
ISBN: 1590592174

web: http://www.oracledba.co.uk
web: http://www.oaktable.net
email: connor_mcdonald@yahoo.com

Coming Soon! "Oracle Insight - Tales of the OakTable"

"GIVE a man a fish and he will eat for a day. But TEACH him how to fish,
and...he will sit in a boat and drink beer all day"

------------------------------------------------------------
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-23-2008, 09:49 AM
Richard Kuhler
 
Posts: n/a
Default Re: Fast bitwise search

Connor McDonald wrote:
> Richard Kuhler wrote:
>
>>kuntz.1507173@bloglines.com wrote:
>>
>>>we have a large table that contains a bitmask field:
>>>MASK NUMBER(19)
>>>
>>>The application then performs a query that includes BITAND(MASK, ?) > 0
>>>condition.
>>>
>>>Is there any way to use an index for this condition. I was thinking
>>>about bitmap indexes for this but could not figure out how to use them
>>>here.

>>
>>Why in the world would you bundle data up into a column like that? I
>>can't imagine why the correct solution isn't to break those bits out
>>into individual columns with descriptive names so people can actually
>>see what information is stored there. Then you could use bitmap indexes
>>on them if performance dictated it (keeping in mind the problems they
>>create).
>>
>>--
>>Richard Kuhler

>
>
> Lets says its 20 attributes, each being boolean. A b-tree index isn't
> going to help since the cardinality is so low.


That's an over simplification. Especially with a bitmask where you are
looking for rows with bits set. What if only 1 row in a 100 million row
table has the attribute value you are looking for? Even if you forget
about histograms, you can use a null-or-set design to create an index
that will just have the rows that have the attribute set.

> So you might indeed be up for a full scan no matter what, at which
> point, a bit mask in a single column may indeed be the best way to go


Sure, but should we design a data model purely so it gives the best
performance possible? When does usability come into the equation?

--
Richard Kuhler

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-23-2008, 09:49 AM
ctcgag@hotmail.com
 
Posts: n/a
Default Re: Fast bitwise search

Richard Kuhler <noone@nowhere.com> wrote:
> ctcgag@hotmail.com wrote:
> > Richard Kuhler <noone@nowhere.com> wrote:
> >
> >>kuntz.1507173@bloglines.com wrote:
> >>
> >>>we have a large table that contains a bitmask field:
> >>>MASK NUMBER(19)
> >>>
> >>>The application then performs a query that includes BITAND(MASK, ?) >
> >>>0 condition.
> >>>
> >>>Is there any way to use an index for this condition. I was thinking
> >>>about bitmap indexes for this but could not figure out how to use them
> >>>here.
> >>
> >>Why in the world would you bundle data up into a column like that? I
> >>can't imagine why the correct solution isn't to break those bits out
> >>into individual columns with descriptive names so people can actually
> >>see what information is stored there. Then you could use bitmap
> >>indexes on them if performance dictated it (keeping in mind the
> >>problems they create).

> >
> > I don't know why the OP would bundle data up like that, but I do it
> > because N+512 columns in a table is just too many, and N+2048 columns
> > is way too many. (Of course, I have little hopes of getting bitmap
> > indices to work effectively on this data anyway.)
> >
> > Xho

>
> Wow, you really have a tuple with 2048 distinct and meaningful
> attributes?


They certainly are distinct. I don't know about meaningful. Bit #478
being on means that the underlying object has a sub-component which hashes
to 478 (or maybe to 479, I can never remember).

> What is this application if I might ask?


Cheminformatics (and some bioinformatics). Some queries in this
field have the unfortunate property that testing a query against
an object to determine if they match is an NP-complete task, and can take
anywhere from 0.01 second to 10 seconds per row. But you can come up with
clever ways to create bitstrings from both object and query such that,
for each bit that is "on" in the query, there is a 100% chance of it also
being on in a matching object while only a 50% (or so) chance of it being
on in a non-matching object. If you test hundreds or thousands of bits,
almost all the non-matching objects fall out, leaving you to do the slow,
accurate, NP-complete check on only a handful of objects instead of
millions.

> Even if you
> convinced me that they absolutely can't be columns, I'd wonder why they
> can't be rows in a related table.


In my case the entire reason for using the bitstring is for performance,
and I very much doubt doing this would increase performance.

Not that this has much to do with the original question any more, but
you did ask

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-23-2008, 09:50 AM
Frank van Bortel
 
Posts: n/a
Default Re: Fast bitwise search

Richard Kuhler wrote:

> Frank van Bortel wrote:
>
>> Richard Kuhler wrote:
>>
>>> kuntz.1507173@bloglines.com wrote:
>>>
>>>> we have a large table that contains a bitmask field:
>>>> MASK NUMBER(19)
>>>>
>>>> The application then performs a query that includes BITAND(MASK, ?) > 0
>>>> condition.
>>>>
>>>> Is there any way to use an index for this condition. I was thinking
>>>> about bitmap indexes for this but could not figure out how to use them
>>>> here.
>>>
>>>
>>> Why in the world would you bundle data up into a column like that? I
>>> can't imagine why the correct solution isn't to break those bits out
>>> into individual columns with descriptive names so people can actually
>>> see what information is stored there. Then you could use bitmap
>>> indexes on them if performance dictated it (keeping in mind the
>>> problems they create).
>>>
>>> --
>>> Richard Kuhler

>>
>>
>> Why would Oracle use this internally all over? (Check sql.bsq).
>> For one, you can add a new mask, without adding columns to
>> the design.

>
>
> No offense, but if you mimic everything I've seen done by Oracle's own
> developers then you're going to make many mistakes. They aren't gods.
> In fact, why not just have one table with one BLOB column, store
> everything in that and we'd never have to change the data model again?
> STOP! I'm not suggesting you do that! (although I've seen it done with
> disastrous results). The reason is that it defeats one of the major
> purposes of having a data model. Namely, so that data is stored in a
> well-described manner so a wide variety of people can access it
> intuitively and easily. This bitmask scenario is extremely counter to
> that.
>
> Besides, why is adding columns to a table to support new functionality a
> bad thing? Heaven forbid it might actually work to inform people that
> it exists.
>
> --
> Richard Kuhler
>


You do need to rewrite every bit of PL/SQL and Java; bitwise
operations do not require that.
Apart from that - it seems quite fast.
And one bitand(column) is easier to code
than where col1 = 1 and col2 = 'Y' and col3=...
.....
and col75...

And I do not mimic Oracle code expert (wish I had the knowledge),
but have not heard any technical reasons why I shouldn't use bitand.
Datamodels are not the same as technical implementations.
--

Regards,
Frank van Bortel

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:37 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556