Skip to content

Commit

Permalink
[doc](sql) bitmap-1 func (#1852)
Browse files Browse the repository at this point in the history
## Versions 

- [x] dev
- [x] 3.0
- [x] 2.1
- [ ] 2.0

## Languages

- [x] Chinese
- [x] English

## Docs Checklist

- [ ] Checked by AI
- [ ] Test Cases Built
  • Loading branch information
catpineapple authored Jan 22, 2025
1 parent 4ff019f commit 2b55bbe
Show file tree
Hide file tree
Showing 60 changed files with 2,115 additions and 1,302 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,61 +24,74 @@ specific language governing permissions and limitations
under the License.
-->

## bitmap_and_count
### description
#### Syntax
## Description

`BigIntVal bitmap_and_count(BITMAP lhs, BITMAP rhs, ...)`
Computes the intersection of two or more input BITMAPs and returns the number of intersections.

Calculate the intersection of two or more input bitmaps and return the number of intersections.

### example
## Syntax

```sql
BITMAP_AND_COUNT(<bitmap>, <bitmap>,[, <bitmap>...])
```
MySQL> select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_empty());
+---------------------------------------------------------------+
| bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_empty()) |
+---------------------------------------------------------------+
| 0 |
+---------------------------------------------------------------+

## Parameters

MySQL> select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_from_string('1,2,3'));
+----------------------------------------------------------------------------+
| bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2,3')) |
+----------------------------------------------------------------------------+
| 3 |
+----------------------------------------------------------------------------+
| Parameter | Description |
|------------|----------------------------------------------------------------|
| `<bitmap>` | One of the original BITMAPs whose intersection is being sought |

## Return Value

MySQL> select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5'));
Returns an integer
- If the parameter has a null value, it returns NULL

## Examples

```sql
select bitmap_and_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5'));
```

```text
+----------------------------------------------------------------------------+
| bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('3,4,5')) |
+----------------------------------------------------------------------------+
| 1 |
+----------------------------------------------------------------------------+
```

MySQL> select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'));
```sql
select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'));
```

```text
+-------------------------------------------------------------------------------------------------------------+
| (bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'))) |
+-------------------------------------------------------------------------------------------------------------+
| 2 |
+-------------------------------------------------------------------------------------------------------------+
```

```sql
select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'),bitmap_empty());
```

MySQL> select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'),bitmap_empty());
```text
+-----------------------------------------------------------------------------------------------------------------------------+
| (bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'), bitmap_empty())) |
+-----------------------------------------------------------------------------------------------------------------------------+
| 0 |
+-----------------------------------------------------------------------------------------------------------------------------+
```

```sql
select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'), NULL);
```

MySQL> select bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'), NULL);
```text
+-------------------------------------------------------------------------------------------------------------------+
| (bitmap_and_count(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'), NULL)) |
+-------------------------------------------------------------------------------------------------------------------+
| NULL |
+-------------------------------------------------------------------------------------------------------------------+
```

### keywords

BITMAP_AND_COUNT,BITMAP
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,54 @@ specific language governing permissions and limitations
under the License.
-->

## bitmap_and_not_count,bitmap_andnot_count
### description
#### Syntax
## Description

`BITMAP BITMAP_AND_NOT_COUNT(BITMAP lhs, BITMAP rhs)`
Performs a NOT operation on two BITMAPs and returns the number of elements in the result set. The first input parameter is called `base BITMAP` and the second is called `exclusion BITMAP`.

Calculate the set after lhs minus intersection of two input bitmaps, return the new bitmap size.
## Alias

- BITMAP_ANDNOT_COUNT

### example
## Syntax

```sql
BITMAP_AND_NOT_COUNT(<bitmap1>, <bitmap2>)
```
mysql> select bitmap_and_not_count(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')) cnt;

## Parameters

| Parameter | Description |
|-------------|----------------------------------|
| `<bitmap1>` | `Base BITMAP` to be negated |
| `<bitmap2>` | `Exclusion BITMAP` to be negated |

## Return Value

Returns an integer.
- If the parameter has a null value, returns NULL

## Examples

```sql
select bitmap_and_not_count(null, bitmap_from_string('1,2,3')) banc1, bitmap_and_not_count(bitmap_from_string('1,2,3') ,null) banc2;
```

```text
+-------+-------+
| banc1 | banc2 |
+-------+-------+
| 0 | 0 |
+-------+-------+
```

```sql
select bitmap_and_not_count(bitmap_from_string('1,2,3'), bitmap_from_string('3,4,5')) banc;
```

```text
+------+
| cnt |
| banc |
+------+
| 2 |
+------+
```

### keywords

BITMAP_AND_NOT_COUNT,BITMAP_ANDNOT_COUNT,BITMAP
```
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,78 @@ specific language governing permissions and limitations
under the License.
-->

## bitmap_and_not,bitmap_andnot
### description
#### Syntax
## Description

`BITMAP BITMAP_AND_NOT(BITMAP lhs, BITMAP rhs)`
Perform a NOT operation on two BITMAPs and return the result. The first input parameter is called `base BITMAP` and the second is called `exclude BITMAP`.

Calculate the set after lhs minus intersection of two input bitmaps, return the new bitmap.
## Alias

### example
- BITMAP_ANDNOT

## Syntax

```sql
BITMAP_AND_NOT(<bitmap1>, <bitmap2>)
```

## Parameters

| Parameter | Description |
|-------------|----------------------------------|
| `<bitmap1>` | `Base BITMAP` to be negated |
| `<bitmap2>` | `Exclusion BITMAP` to be negated |

## Return Value

Returns a BITMAP.
- If the parameter has a null value, returns NULL

## Examples

```sql
select bitmap_count(bitmap_and_not(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5'))) cnt;
```
mysql> select bitmap_count(bitmap_and_not(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5'))) cnt;

```text
+------+
| cnt |
+------+
| 2 |
+------+
```

mysql> select bitmap_to_string(bitmap_and_not(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')));
```sql
select bitmap_to_string(bitmap_and_not(bitmap_from_string('1,2,3'),bitmap_from_string('3,4,5')));
```

```text
+--------------------------------------------------------------------------------------------+
| bitmap_to_string(bitmap_and_not(bitmap_from_string('1,2,3'), bitmap_from_string('3,4,5'))) |
+--------------------------------------------------------------------------------------------+
| 1,2 |
+--------------------------------------------------------------------------------------------+
```

```sql
select bitmap_to_string(bitmap_and_not(bitmap_from_string('1,2,3'),bitmap_empty()));
```

mysql> select bitmap_to_string(bitmap_and_not(bitmap_from_string('1,2,3'),bitmap_empty())) ;
```text
+-------------------------------------------------------------------------------+
| bitmap_to_string(bitmap_and_not(bitmap_from_string('1,2,3'), bitmap_empty())) |
+-------------------------------------------------------------------------------+
| 1,2,3 |
+-------------------------------------------------------------------------------+
```

```sql
select bitmap_to_string(bitmap_and_not(bitmap_from_string('1,2,3'),NULL));
```

mysql> select bitmap_to_string(bitmap_and_not(bitmap_from_string('1,2,3'),NULL));
```text
+---------------------------------------------------------------------+
| bitmap_to_string(bitmap_and_not(bitmap_from_string('1,2,3'), NULL)) |
+---------------------------------------------------------------------+
| NULL |
+---------------------------------------------------------------------+
```

### keywords

BITMAP_AND_NOT,BITMAP_ANDNOT,BITMAP
Original file line number Diff line number Diff line change
Expand Up @@ -24,67 +24,61 @@ specific language governing permissions and limitations
under the License.
-->

## bitmap_and
### description
#### Syntax
## Description

`BITMAP BITMAP_AND(BITMAP lhs, BITMAP rhs, ...)`
Computes the intersection of two or more input BITMAPs and returns a new BITMAP.

Compute intersection of two or more input bitmaps, return the new bitmap.
## Syntax

### example
```sql
BITMAP_AND(<bitmap>, <bitmap>,[, <bitmap>...])
```

## Parameters

| Parameter | Description |
|------------|----------------------------------------------------------------|
| `<bitmap>` | One of the original BITMAPs whose intersection is being sought |

## Return Value

Returns a BITMAP
- If the parameter has a null value, it returns NULL

## Examples

```sql
select bitmap_to_string(bitmap_and(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5')));
```
mysql> select bitmap_count(bitmap_and(to_bitmap(1), to_bitmap(2))) cnt;
+------+
| cnt |
+------+
| 0 |
+------+
mysql> select bitmap_to_string(bitmap_and(to_bitmap(1), to_bitmap(2)));
+----------------------------------------------------------+
| bitmap_to_string(bitmap_and(to_bitmap(1), to_bitmap(2))) |
+----------------------------------------------------------+
| |
+----------------------------------------------------------+
mysql> select bitmap_count(bitmap_and(to_bitmap(1), to_bitmap(1))) cnt;
+------+
| cnt |
+------+
| 1 |
+------+
MySQL> select bitmap_to_string(bitmap_and(to_bitmap(1), to_bitmap(1)));
+----------------------------------------------------------+
| bitmap_to_string(bitmap_and(to_bitmap(1), to_bitmap(1))) |
+----------------------------------------------------------+
| 1 |
+----------------------------------------------------------+
MySQL> select bitmap_to_string(bitmap_and(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5')));

```text
+-----------------------------------------------------------------------------------------------------------------------+
| bitmap_to_string(bitmap_and(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'))) |
+-----------------------------------------------------------------------------------------------------------------------+
| 1,2 |
+-----------------------------------------------------------------------------------------------------------------------+
```

MySQL> select bitmap_to_string(bitmap_and(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'),bitmap_empty()));
```sql
select bitmap_to_string(bitmap_and(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'),bitmap_empty()));
```

```text
+---------------------------------------------------------------------------------------------------------------------------------------+
| bitmap_to_string(bitmap_and(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'), bitmap_empty())) |
+---------------------------------------------------------------------------------------------------------------------------------------+
| |
+---------------------------------------------------------------------------------------------------------------------------------------+
```

MySQL> select bitmap_to_string(bitmap_and(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'),NULL));
```sql
select bitmap_to_string(bitmap_and(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'),NULL));
```

```text
+-----------------------------------------------------------------------------------------------------------------------------+
| bitmap_to_string(bitmap_and(bitmap_from_string('1,2,3'), bitmap_from_string('1,2'), bitmap_from_string('1,2,3,4,5'), NULL)) |
+-----------------------------------------------------------------------------------------------------------------------------+
| NULL |
+-----------------------------------------------------------------------------------------------------------------------------+
```

### keywords

BITMAP_AND,BITMAP
Loading

0 comments on commit 2b55bbe

Please sign in to comment.