Say you'd a lengthy variety of chars which are either 1 or , type of just like a bitvector, but on the database column. How does one query to be aware what values are positionedOrno set? Say you should know when the char 500 and char 1500 are "true" or otherwise.

SELECT
  Id
FROM
  BitVectorTable
WHERE
  SUBSTRING(BitVector, 500, 1) = '1'
  AND SUBSTRING(BitVector, 1000, 1) = '1'

No index can be used as this type of query, though. If you have many rows, this can get slow very rapidly.

Edit: On SQL Server a minimum of, all built-in string functions are deterministic. Which means you can consider the chance to create calculated posts in line with the SUBSTRING() results for the entire combined value, putting an index on each of them. Card inserts is going to be reduced, table size increases, but searches is going to be really fast.

SELECT
  Id
FROM
  BitVectorTable
WHERE
  BitVector_0500 = '1'
  AND BitVector_1000 = '1'

Edit #2: The limits for SQL Server are:

  • 1,024 posts per normal table
  • 30.000 posts per "wide" table

In MySQL, something using substring like

select foo from bar 
where substring(col, 500,1)='1' and substring(col, 1500,1)='1';

This is pretty inefficient though, you might like to re-think your schema. For instance, you can store every bit individually to tradeoff space for speed...

create table foo
(
   id int not null,
   bar varchar(128),
   primary key(id)
);

create table foobit
(
   int foo_id int not null,
   int idx int not null,
   value tinyint not null,

   primary key(foo_id,idx),
   index(idx,value)
);

Which may be queried

   select foo.bar from foo
   inner join foobit as bit500
      on(foo.id=bit500.foo_id and bit500.idx=500)
   inner join foobit as bit1500
      on(foo.id=bit1500.foo_id and bit1500.idx=1500)
   where
      bit500.value=1 and bit1500.value=1;

Clearly consumes more storage, but ought to be faster for individuals query procedures being an index is going to be used.

I'd convert the column to multiple bit-posts and rewrite the appropriate code - Bit masks are extremely considerably faster than string evaluations. But when you cannot do this, you have to use db-specific functions. Regular expressions happens to be an option

-- Flavor: MySql
SELECT * FROM table WHERE column REGEXP "^.{499}1.{999}1"
select substring(your_col, 500,1) as char500,
substring(your_col, 1500,1) as char1500 from your_table;