microsoft / azuredatastudio

Azure Data Studio is a data management and development tool with connectivity to popular cloud and on-premises databases. Azure Data Studio supports Windows, macOS, and Linux, with immediate capability to connect to Azure SQL and SQL Server. Browse the extension library for more database support options including MySQL, PostgreSQL, and MongoDB.
https://learn.microsoft.com/sql/azure-data-studio
MIT License
7.58k stars 904 forks source link

Invalid row generated at statement result #25861

Open andrecj93 opened 2 months ago

andrecj93 commented 2 months ago

Type: Bug

When making an sql statement, azure data studio is generating an invalid row at the end of the result, resulting in a correct overview of the statement. This happened when connected to SQL.

Azure Data Studio version: azuredatastudio 1.48.0 (4970733324ef8254b7c22a5dc55af7f8a1dea93f, 2024-02-27T00:05:08.293Z) OS version: Windows_NT x64 10.0.22635 Restricted Mode: No Preview Features: Enabled Modes:

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz (16 x 3600)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|undefined| |Memory (System)|31.93GB (8.80GB free)| |Process Argv|| |Screen Reader|no| |VM|0%|
Extensions (3) Extension|Author (truncated)|Version ---|---|--- azure-cosmosdb-ads-extension|Mic|0.4.5 net-6-runtime|Mic|1.1.0 azdata-sanddance|msr|4.1.1
kburtram commented 2 months ago

@andrecj93 could you please add additional details on which SQL statement is generating an invalid row, and any other details that would help repro this bug?

I wasn't able to repro using a simple SQL statement, for example below.

image

andrecj93 commented 2 months ago

As you can see the last row is showing as null. The UI seems to not update it and I've seen times where it showed random data or the last row would be equal to the penultimate row. If I switch to Messages and back to Results it will show the correct result as you can see in the last screenshot below.

1

2

3

kburtram commented 2 months ago

@caohai do you any ideas what could be happening here? I'm still unable to repro & haven't seen this before. The only thing coming to mind is that maybe there is some timing issue if the rows contain many columns for BLOB, XML, JSON and it's taking a long time to move the results to the UI, but I only see one JSON field in the screenshot above.

caohai commented 2 months ago

@kburtram I did a quick search in the issues and found a few that appear to be related. In particular this issue https://github.com/microsoft/azuredatastudio/issues/24052 Cheena created last year seems to be very similar to this one. I tried to test with some large strings in the result but still couldn't get a repro. I've reached out to Cheena to see if we can get a consistent repro.

@andrecj93 Can you share the rough size of the DraftData field?

andrecj93 commented 2 months ago

@caohai The column can hold varchar max.

Here's the char count for the same query I've shown you. Prova123

Take a look at one of the runs that generated absurd data that doesnt exist. ProvaWtf

Yes, I think Its related to the size of what the column hold as I've seen this happen in another table that holds large AI prompts.

caohai commented 2 months ago

@kburtram I was able to repro both issues, I believe they are two different bugs. Here are the repro scripts:

CREATE TABLE TestTable1 (
    name varchar(max),
    id text,
);

INSERT INTO TestTable1 (name, id) VALUES (REPLICATE(CONVERT(varchar(max), 'V'), 2147483) , 'vvvvvv');
INSERT INTO TestTable1 (name, id) VALUES (REPLICATE(CONVERT(varchar(max), 'U'), 2147483) , 'uuuuuu');

-- id and name might not render for the last row, you can still copy the cell value
-- will render if you go to Messages then back
select id, name, len(name) as charcount, null as TEST from TestTable1

The above script reproduces this issue for me (not 100%, if I click Run multiple times, 20% of the time the result might correctly render, ).

image
CREATE TABLE TestTable2 (
    name varchar(max),
    id text,
);

-- can take a few minutes to finish
INSERT INTO TestTable2 (name, id) VALUES (REPLICATE(CONVERT(varchar(max), 'W'), 2147483646) , 'wwwww');

-- will render invalid data while the qurey is running, eventually query fails with
-- "Query failed: Array dimensions exceeded supported range." and the invalid data is till in the grid.
-- I've already set mssql.query.maxCharsToStore to 2147483647
select id, name, len(name) as charcount, null as TEST from TestTable2

This script reproduces https://github.com/microsoft/azuredatastudio/issues/24052 as well as the invalid data shown in the second screenshot of https://github.com/microsoft/azuredatastudio/issues/25861#issuecomment-2305891915

Screenshot 2024-08-22 at 17 08 31 image