How about filtering the joined layer for null values? Right click the joined layer and choose filter. QGIS will ask you to create a virtual layer to filter since it is a join-layer. Then you can filter the virtual layer with:
"nameOfColumnThatShouldHaveData" IS NOT NULL
I created a small test data set where I joined the column "data" from the layer "table" onto the point layer "joinedLayer". See the images below for the process.
Right click and filter the joined layer
Press yes to create a virtual layer
Right click the new, virtual layer and press filter again
Filter out null values in the columns added by the join ("table_data" in my case, since it was prefixed in the join process)
And here is the result tables. As you can see, the virtual layer has less features than the joinedLayer, since the NULL values are filtered out. You can also see the differing feature count in the layer list.
You should get the 40 000 rows that has the new column with data in it. You can right click the virtual layer and select "Show feature count" to make sure it is 40 000.
Not sure if this is impacted by the large number of rows, but the process works for a small dataset.
This is not a pyQGIS answer of course, but I got the impression in the comment discussion that pyQGIS was not a requirement.
Another caveat is that if the input join data contains null values, you will filter out those as well of course, thus filtering out rows that were actually joined. You could string together a compound filter to check all joined columns if some have data and some have null like so:
("column1" is not null) AND ("column2" is not null) ...
... and so on.